I'm working on refactoring my university's mobile applications API.
The main idea was to move it from Jsoup to Retrofit because of the better classes structure (and because Google recommends so).
I found that previous version was built around this call:
Jsoup.connect(url)
.data(request.getArgs())
.ignoreContentType(true)
.method(Connection.Method.POST)
.timeout(timeout)
.execute();
Where .data()
args is Map<Key, Value>
, which is transforming into a query like url?key1=value1&key2=vaule2&...&keyN=valueN
as followed in the Jsoup docs.
I have tested this call, and it works properly – returning a JSON object.
So with this info I was trying to recreate such behavior using Retrofit2 API. I have created a service interface:
public interface MyService {
@POST("url")
Call<ResponseBody> myRequest(@Query("key1") String value1, @Query("key2") String value2);
}
But when I tried to call this request, as the response body I got a 404 HTML-page instead of the expected JSON.
So here is my answer: is there any difference between how these two solutions forming their requests? I was trying to go deeper, but found nothing.