-
Notifications
You must be signed in to change notification settings - Fork 6k
[Android][Volley] Post requests with json body raise exception Invalid header #5575
Copy link
Copy link
Closed
Milestone
Description
Description
Generated by swagger code for android for volley library incorrect handles post requests with json body. When I use api method with json body, I receive an error response with status = 400 and message "Invalid header". The problem is in this code fragment in ApiInvoker class:
request = new PostRequest(url, headers, contentType, new StringEntity(serialize(body), "UTF-8"), stringRequest, errorListener);By default in my case code
new StringEntity(serialize(body), "UTF-8")creates an entity with text/plain content type. That is wrong because server expects application/json content type.
Swagger-codegen version
Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues
Suggest a Fix
To fix it is sufficient to replace code
request = new PostRequest(url, headers, contentType, new StringEntity(serialize(body), "UTF-8"), stringRequest, errorListener);by
StringEntity entity = new StringEntity(serialize(body),"UTF-8");
entity.setContentType("application/json");
request = new PostRequest(url, headers, contentType, entity, stringRequest, errorListener);Reactions are currently unavailable