Android and Retrofit HTTP POST yields HTTP 400 : Bad Request

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Android and Retrofit HTTP POST yields HTTP 400 : Bad Request

ElliotB
When running a Retrofit-based HTTP POST, the Cherrypy server responds with HTTP 400
However, when the same request is run with POSTMAN, the Cherrypy server processes the request.

Some details:

The request:
public void sendPost(String title, String body) {
mAPIService.savePost(title, body, 19).enqueue(new Callback<Post>() {
@Override
public void onResponse(Call<Post> call, Response<Post> response) {
if (response.code() == 400) {
Log.v("Error code 400",response.message().toString());
Log.v("Error code 400",response.headers().toString());
Log.v("Error code 400",response.errorBody().toString());


The verbose Android log:
2019-03-18 14:22:57.638 32433-32433/com.example.android.retrofitrestfulapi V/Error code 400: Bad Request
2019-03-18 14:22:57.639 32433-32433/com.example.android.retrofitrestfulapi V/Error code 400: Content-Type: text/html;charset=utf-8
    Server: CherryPy/14.0.0
    Date: Mon, 18 Mar 2019 18:22:59 GMT
    Content-Length: 2430
    Access-Control-Allow-Origin: *




The Interface: APIService.java contains:

    @Headers({"Content-Type: application/json", "Accept: application/json" , "Access-Control-Allow-Origin: *", })
@POST("/userprofileinfo")
@FormUrlEncoded
Call<Post> savePost(@Field("title") String title,
@Field("body") String body,
@Field("userId") long userId);
}

Happy to include the full code but wondered if anyone has seen this occur where the Cherrypy server returns HTTP 400

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.