Request method 'POST' not supported Retrofit Android - android

I am getting this error - Request method 'POST' not supported but I am not using POST type.
#GET("ads/getAdsList")
Call<ApiResponse<List<HomeAdModel>>> getAdsList();
I am calling it like above. But getting this error
D/OkHttp: --> POST http://abc/foodS/api/ads/getAdsList
D/OkHttp: <-- 405 http://abc/foodS/api/ads/getAdsList (1661ms)
D/OkHttp: {"timestamp":"2020-07-22T15:32:42.207+0000","status":405,"error":"Method Not Allowed","message":"Request method 'POST' not supported","path":"/foodS/api/ads/getAdsList"}
When I check it in postman, it works. Here is the screenshot.

It seems like your HTTP client changes GET to POST method which is not supported by the backend.
You can change the server side response return to "307" code or, switch to OKHTTP or Volley library to be able to connect to the backend using custom network interceptor.
According to: https://github.com/square/retrofit/issues/1762#issuecomment-215086267
And read: https://github.com/square/okhttp/issues/2262#issuecomment-172933936

Related

403 on Android for Reddit API but not on browser

When making a request with Retrofit using an OKHttp Client with interceptors to add headers:
(Authorization: Bearer + access_token)
(User-Agent: "user_agetn_as_described_by_reddit")
Using the oauth.reddit.com/.json URL as recommended by Reddit, I get a 403. Now, when I do this same thing on Postman or something similar, I get a 200 and the expected JSON.
Is anyone aware of something related to Android or Retrofit or OKHttp that could be causing me this pain?
I was using the auth code instead of the access_token to make my requests. A mistake from my side. You should use the auth code to make a token request.

how to set server Session management with volley Request?

My web server program is written in nodejs , But it does not manage session when i send request from my android app ,I have set the header along with my request, but I'm getting the same response from the server as "Session does not exist" , I added Cookie token along with the request header , something is missing in my Volley request Header .The code below shows my Volley response Header ... can anybody help me to make Volley request header with the cookie token ?
{
Connection=keep-alive,
Content-Length=216,
Content-Type=application/json; charset=utf-8,
Date=Wed,
18 Jan 2017 06:12:11 GMT,
ETag=W/"d8-oF3uHVo3IiU9RmPHXIfBcA",
Server=nginx/1.10.0 (Ubuntu),
set-cookie=connect.sid=s%3ACeQpRX68rrYC6bebVi5F15hEN8uUmetO.GPKqnHv9VYNH83ztga3YnicAsvZ%2FSB28xUcrRGRa2sA; Path=/,
X-Android-Received-Millis=1484719931455,
X-Android-Response-Source=NETWORK 200,
X-Android-Selected-Protocol=http/1.1,
X-Android-Sent-Millis=1484719930801,
X-Powered-By=Express
}

Android OKHttp and Retrofit return 304 error

I'm develop an android application using OKHttp and Retrofit to send request to skyscanner API.
But sometime I got 304 response and this response have no body content. So I can't parse the body content to my object and that's why my listview show nothing.
Can anyone help me to avoid 304 error.
304 is not an error. 304 refers to a redirect, and is the responsibility of the client to handle it.
http://www.checkupdown.com/status/E304.html
You are most likely doing a GET request on a document that has not changed, and you should depend on your cache to handle that for you.

HTTP Response logging if using Ion

We can set logging if we use Ion to make HTTP connection to server as below
Ion.getDefault(getContext()).configure().setLogging("MyLogs", Log.DEBUG);
But we can't see the HTTP response from server from log that generated.
How to see HTTP response ?
Ion does not put the response body into the logs, as the body may be enormous, binary, etc.
If you want to log the body, do so yourself in the setCallback.

Http requests from android app to django server

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?

Categories

Resources