2017-06-02 24 views
0

我有一个端点,在这里我放入一些数据,其中内容类型应该是表格数据。通过改进发送表格数据2

我使用

@FormUrlEncoded 
@PUT("/api/v1/clients/profile/all_details") 
Call<ResponseBody> postUserProfile(@FieldMap Map<String, String> userParams); 

但发送请求,表单数据进行编码像

food_allergy=%5Beggs%2C%20milk%2C%20nuts%2C%20none%5D&diet_prefer=Non%20Vegetarian&age=25&exercise_level=Moderate&email=Email&name=Veeresh&height=175&prompt-qgreet3=I%27m%20ready%21&gender=Female&health_condition=%5Bdiabetes%2C%20PCOD%5D&weight=69 

如何删除编码?

我想这个博客

https://futurestud.io/tutorials/retrofit-send-data-form-urlencoded-using-fieldmap

+0

编写一个启动该检查为%第一项及作为最后一个项目一个正则表达式。 –

+0

任何其他替代方案,而不是正则表达式? –

回答

0

如果你不想编码形式的数据,那么你可以尝试这样的

@PUT("/api/v1/clients/profile/all_details") Call<ResponseBody> postUserProfile(@QueryMap Map<String, String> userParams);

编辑1

@Multipart 
     @PUT("/api/v1/clients/profile/all_details") 
     Call<ResponseBody> postUserProfile(@Part(username) RequestBody username, @Part(password) RequestBody password); 

以下是如何从String获取requestBody。

String username = "username"; 
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), username); 

String password = "password"; 
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), password); 
+0

不,它不能是@QueryMap,QueryMap的作品添加到网址 –

+0

我编辑了我的答案,你可以检查与 –

+0

在@Part中使用的密钥是动态的,我不能硬编码它们 –

0

你可以先全部更换所有%使用

string.replace("%",""); 

,并做其他的方式相同。

0

@FieldMap有一个名为encoded的元素,默认为false

如果您将其设置为true,则表示我的数据已被编码,并且我不希望Retrofit处理编码。

@FieldMap(encoded = true) Map<String, String> userParams