Retrofit converted POST to GET - android

I have really strange problem. Use retrofit to send request.
#POST("api/v2/reviews/vote/{vote}/dislike/{dislike}")
Single<SimpleResponse> postReviewLike(#Path("vote") Integer vote, #Path("dislike") Integer dislike);
This is my request. But when I send it to server - retrofit converted it to GET request. Bellow photo for a proof.
Can you suggest, what it can be? And how I can fix it.
With other POST request all is good, if I use #Field.

Could you please try this out using the #Body annotation?
#POST("api/v2/reviews/vote/{vote}/dislike/{dislike}")
Single<SimpleResponse> postReviewLike(#Body #Path("vote") Integer vote, #Path("dislike") Integer dislike);

Problem was with redirect. Adding '/' dislike/{dislike}/ helped me.

Related

Sending Array as Param in Retrofit Get Request A

I am trying to send an array as parameter in GET request in Retrofit
Eg: prod = [1,2,3,4]
Tried almost every solution present on Stack OverFlow, GitHub
Non of them worked
Can someone explain how to make an array and send get request in RetroFit
Thankyou in advance!
You can try like this
#GET(".....")
Call<ResponseBody> getSomthingApi(#Query("prod") ArrayList<String> values);

Patch request using Retrofit2 not working Android

I have created patch request using Retrofit2.
#PATCH("/tests/{id}")
Call<Test> updateTest(#Path("id") int id, #Body Test test);
This request working using Postman. It returns updated JSON of Test class. But it is not working using Retrofit.
Any help ?
Add "/" at the end of URL.
#PATCH("/tests/{id}/")
well you should display your error but in general in retrofit you should pass your path parameter before so it will be something like this
#PATCH("/tests/{id}")
Call<Test> updateTest(#Path("id") int id, #Body Test test);
hope this helps
please check method (GET , POST , DELETE) and change code to :
#GET("/tests/{id}")

Retrofit2: #Path parameter in OkHttp Interceptor

In our API we have sign based on both #Query and #Path parameters. Everyone suggests to use OkHttp Interceptor for this. Everything is fine with query params, but I don't think there is any way to get path parameter values and names. For example:
/api/{version}/books/{id}
/api/v1.1/books/10
To make a correct sign, I need Map:
{"id":"10", "version":"v1.1"}
Am I missing something?
Follow the following code, probably your problem will be solved.
/api/{version}/books/{id}
public type method(#Path("version") String versionValue,#Path("id") String idValue,.....)

Android Retrofit api link presntation

I'm still beginner on retrofit API for android, but I still didn't get it !!
I know about the Annotation #Path and #Query but I still don't know what is the use of #Field
and I also know about #POST and #GET but I don't know what is #PUT
and one last question.. lets say that in my API I created the following service.
#GET("/bookmarks")
public abstract void bookmarks(#Query("countryCode") String paramString, #Query("limit") int paramInt1, Callback<BookmarksResult> paramCallback);
how this call is actually presented as a link?? I mean would it be like this
http://www.example.com/api/bookmarks?countryCode=X&limit=X
please some help my whole day on this and I still don't have good answers
thanks
if your baseUrl is http://www.example.com/api the answer is yes. The url will be resolved in
http://www.example.com/api/bookmarks?countryCode=X&limit=X
and the same applies for the other request methods.
I would use #QueryMap instead of passing more than one #Query, but that's more a matter of taste.
I just notice that your method is marked as abstract. I am pretty sure that one of the constraints of retrofit is that you have to use an interface to declare your endpoints

Bad Request as Response

I tried to get the facebook wall data.I got my access token by using
accesstoken=Login.mFacebook.getAccessToken();
Log.e("accesstoken",accesstoken);
But while calling
String wallres=UrltoValue.getValuefromUrl("https://graph.facebook.com/me/feed? access_token=accesstoken");
Log.e("wall res",wallres);
I am getting Bad Request as response
By calling this code you say that accesstoken is literally part of the URL.
String wallres=UrltoValue.getValuefromUrl("https://graph.facebook.com/me/feed? access_token=accesstoken");
I think you meant to do this, so that you use the previously defined variable accesstoken:
String wallres=UrltoValue.getValuefromUrl("https://graph.facebook.com/me/feed? access_token=" + accesstoken);
I have already a problem like this. Try remove the spaces or convert it to %20.
String wallres=UrltoValue.getValuefromUrl("https://graph.facebook.com/me/feed?access_token=accesstoken");
Log.e("wall res",wallres);
Regards, Hugo Pedrosa

Categories

Resources