Retrofit 2 Multipart POST request sends extra quotes to PHP

后端 未结 4 1797
广开言路
广开言路 2021-02-05 17:08

Using Retrofit 2.0.1, there is a call function in my API interface defined in Android App:

@Multipart
@POST(\"api.php\")
Call doAPI(
  @Part(         


        
4条回答
  •  有刺的猬
    2021-02-05 17:37

    I faced this on my project today and this is how I solved it. I changed @Part on my string and other primitive values to @Query, and for file (in my case image) i used @Part. Looks like @Query treats strings in a different way compared to @Part.

    So my answer to original question would look like this:

    @Multipart
    @POST("api.php")
    Call doAPI(
      @Query("lang") String lang,
      @Part("file\"; filename=\"image.jpg") RequestBody file
    );
    

    This should send string values without unwanted quotes. Sadly, I cant explain why this works, it has something to do with @Part encoding of data.

提交回复
热议问题