0

I am trying to submit my json to server with retrofit post method.

if my server used apache server it's working but in case of nginx server it's not working ..

I am trying to explain with dummy api. what am I doing?

URL:

    https://mysite_url/3.6.2/create_dummy_data

Payload:

    {"access_token":"476be4412cef4a3490c2fa2cef5b4cfa","distance":"2000","credit":"200","duration":"10","competitor_id":"180"}

Here I am doing for handle this:

    //@headers({"Content-Type: multipart/form-data"}) this is optional
    //@headers({"Content-Type: application/json"})    this is optional
    @post(URL)
    Observable<PayloadDummy> dummySubmitApi(@query("payload") String s);

SERVER ERROR:

with multipart header:

[error] 6419#6419: *26 FastCGI sent in stderr: "PHP message: PHP Warning: Missing boundary in multipart/form-data POST data in Unknown on line 0" while reading response header from upstream

without any header:

response_status_code 500 request "POST /3.6.2/create_dummy_data HTTP/1.1" 180.151.5.333 - - [25/Jun/2018:11:19:17 +0000] 17730 "-" "okhttp/3.10.0" "-" " {\x22access_token\x22:\x22476be4412cef4a3490c2fa2cef5b4cfa\x22,\x22competitor_id\x22:\x22469\x22,\x22credit\x22:\x22200\x22,\x22distance\x22:\x221000\x22,\x22duration\x22:\x221\x22,\x22type\x22:\x220\x22}""-" "-" "-" "-" {\x22access_token\x22:\x22476be4412cef4a3490c2fa2cef5b4cfa\x22,\x22competitor_id\x22:\x22469\x22,\x22credit\x22:\x22200\x22,\x22distance\x22:\x221000\x22,\x22duration\x22:\x221\x22,\x22type\x22:\x220\x22}

I have used boundary but it's not working ..

How to solved my problem .. please suggest me..

Issue: https://github.com/square/retrofit/issues/2802

2 Answers2

0

make one pojo class for your sending json data. you can genarate pojo class based on robopojo pulgins or refer this site http://www.jsonschema2pojo.org/

after date define this method for api calling..

    @POST("url")
Call<ResponseData> getData(@Body User user);

and also server response pojo class

0

You are passing data in wrong way change this way your error message display you need to pass data in multipart and you are passing in JSON

Milan Pansuriya
  • 2,521
  • 1
  • 19
  • 33
  • response_status_code 500 request "POST /3.6.2/create_dummy_data HTTP/1.1" 180.151.5.333 - - [25/Jun/2018:11:19:17 +0000] 17730 "-" "okhttp/3.10.0" "-" " {\x22access_token\x22:\x22476be4412cef4a3490c2fa2cef5b4cfa\x22,\x22competitor_id\x22:\x22469\x22,\x22credit\x22:\x22200\x22,\x22distance\x22:\x221000\x22,\x22duration\x22:\x221\x22,\x22type\x22:\x220\x22}""-" "-" "-" "-" {\x22access_token\x22:\x22476be4412cef4a3490c2fa2cef5b4cfa\x22,\x22competitor_id\x22:\x22469\x22,\x22credit\x22:\x22200\x22,\x22distance\x22:\x221000\x22,\x22duration\x22:\x221\x22,\x22type\x22:\x220\x22} – Vaibhav Upadhyay Jun 25 '18 at 11:25