Search code examples
androidpostretrofitretrofit2

How to write a @POST request correctly?


I trying to make an @POST request. When I make this request

 @POST("/testAPI")
    @Headers("token: rAhUCUo-wz-Sbtwjt1")
    @FormUrlEncoded
    Call<GetEntires> getEntires(@Field("a")String method,
                                @Field("session")String SessionId);

I get in response: HTML code of site API, but when I make a request in a special program (is Chrome app - ARC) I get the right response, which equals response from documentation of API. Example of request from documentation of API:

curl --header "token: EXAMPLETOKEN" --data "a=new_session" https://bnet.i-partner.ru/testAPI/

Where I made mistake or whatever?

enter image description here

UPDATE: How look request in text from app ARC:

POST /testAPI/ HTTP/1.1
HOST: bnet.i-partner.ru
token: rAhUCUo-wz-Sbtwjt1
content-type: multipart/form-data; boundary=----WebKitFormBoundaryLA3TDEc7BbGOFNMS
content-length: 256

------WebKitFormBoundaryLA3TDEc7BbGOFNMS
Content-Disposition: form-data; name="a"

get_entries
------WebKitFormBoundaryLA3TDEc7BbGOFNMS
Content-Disposition: form-data; name="session "

tThEPaP7uvGWje176p
------WebKitFormBoundaryLA3TDEc7BbGOFNMS--

And response from server:

{
"status": 1,
"data": [
  [],
],
}

Solution

  • for me, it works:

    @Multipart
        @POST("/testAPI")
        fun createPost(@Part("a") post: String?,
                       @Part("session") post2: String?): Call<Post?>?
    

    I used @Part