Http requests from android app to django server - android

I am able to log into the django server using an Http Post request, but when I go to see if the user is authenticated immediately after I am getting a HTTP/1.1 401 UNAUTHORIZED response.
I am using the same DefaultHttpClient for both the post and the get request by means of a static member.
I have already attempted adding the sessionid cookie from the POST request to the GET request as a header.
Is there anything I am missing?

Related

Postman can't send post request to server and server detecting it as get request instead of post

Having issue in postman can't send post request to the server.
So I have
#GetMapping("/{id}")
public blablabla (#PathVariable long id )
#PostMapping("/scan")
public blablablabla(){}
Somehow when I send post request for /scan via postman it returns
Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long';
nested exception is java.lang.NumberFormatException: For input string: \"scan\
But it works fine in my android application.
Is this postman issue?
Thank you
I've got the answer..
In postman, I send http request to my https server.
So it's redirecting it making it a GET request instead of my POST request.

HTTP request Post to a Server where HTTP body is a JSON dictionary

I have a server I need to POST an http request to. The server is located at http://ec2-54-187-236-58.us-west-2.compute.amazonaws.com
I need to execute a POST /ios/search
I'm given that the HTTP body is a JSON dictionary but I cannot connect to the server itself. Nor am I able to see the JSON object in javascript when I enter the server url in a browser. I am using gson library in android to help me execute the http client request, but am getting the
IOException: Connection to http://ec2-54-187-236-58.us-west-2.compute.amazonaws.com/ios/search refused
What am I missing? Or is there an issue with the server url?

Webview post request vs http post request in android

I am working on payment integration with bank. When I do http post request with url and formencoded data , I am getting error html page. But if I am doing the same using webview , I am getting successul otp page of the bank. I am not sure why this response is different. As of now we have to do only http request and wanted the same response as returned by webview. I have tested same request in postman. I am getting successful otp page. What can be possible reason?

HTTP basic request in Android

I want to do a POST HTTP request to the serving to receive some cookies from the server. During this POST request I also need to send some data like login and password. I found a lot of solutions but nothing is working, everything that I found is deprecated.
So the question is: how can I make a HTTP POST request to receive form the server some cookies after?

Android: How to periodically send location to a django server with csrf verification

I want my android app to periodically send location information to my django server.
Based on my research, android client should write the location in JSON, payload JSON in http post, and send http post request to django server periodically. and the http post request is created by the client directly, not from a post form by django. Is it a normal way?
If posting data without form is a general way, then to stop csrf verification, according to the answer of Android sending post requests to django server csrf failing, the android client should
"getting the token from the server and sending that along with the POST data "
(suppose I do not use solution of #csrf_exempt)
My question is where to get the csrftoken cookie?
I do see csrftoken cookie if I send a GET request to a post form, but if posting data directly (without asking for the post form), where does a client get the csrftoken cookie?
You could use an API like tastypie or rest-framework. The only way to get the token is by accessing the page that gives it.

Categories

Resources