Why Retrofit 2 adding double quotes on multipart request data?

DWQA QuestionsCategory: android questionWhy Retrofit 2 adding double quotes on multipart request data?
kamal bunkar Staff asked 1 year ago

I am sending a string to PHP web API using retrofit 2, But retrofit 2 is adding double quotes on the string. For example, if the string is kamalbunkar then on serverside it is receiving like “kamalbunkar”.

How can I remove double quote OR backslash from retrofit request data?

public interface ApiInterface {

    Call<Getproduct> newProduct(
                @Part("customer_name") String name             
1 Answers
kamal bunkar Staff answered 1 year ago

Retrofit2 is using JSON converter to send data to the server. Double quotes is a logical representation of a string.so if retrofit sends data type is a string then in JSON format double quotes will be added to the string.

You have to use convert string into plain text before sending it through retrofit request. on retrofit service-wrapper class convert the string into a plain text using okhttp RequestBody.

 public Call<Getproduct> newProduct(String customername ){
    RequestBody plainString = RequestBody.create(MediaType.parse("text/plain"),customername);
    return mServiceInterface.newProduct( plainString);