I am trying to make the Api call using Retrofit 2 POST method with @Field and @FormurlEncoded in Android but it just doesn't work in Android PIE.
I have integrated Apis using retrofit thousands of time before. But this time I have targeted sdk Android Pie with retrofit version 2.6.1.
The strange thing is the same thing is working perfectly fine with @Body.
So I have gone through following things to check it out but no luck. I also thought that Android 9.0 might causing the security issue but then @Body part should also not be able to run successfully.
https://square.github.io/retrofit/
Android 8: Cleartext HTTP traffic not permitted
How to make https request with ssl certificate in Retrofit
https://developer.android.com/training/articles/security-config.html
My configurations
targetSdkVersion 29
retrofit2Version = '2.6.1'
Url - https://jsonplaceholder.typicode.com/posts
Request (Which is not working - WHY ?)
@Headers({"Content-Type: application/json",
"Cache-Control: no-cache"})
@FormUrlEncoded
@POST("/posts")
Call<BinRespTempPost> post(@Field("title") String title,
@Field("body") String body,
@Field("userId") int userId);
Request which is working
@Headers({"Content-Type: application/json",
"Cache-Control: no-cache"})
@POST("/posts")
Call<BinRespTempPost> post(@Body BinReqTempPost binReqTempPost);
Response
{
id: 101,
title: 'foo',
body: 'bar',
userId: 1
}
The question is why Api call is successful with @Body and Failure with @Field / @FormUrlEncoded ?
--------- UPDATE ----------
URL type - POST
Response on failure - Html response (500 error)