Prevent retrofit from encoding my http request body

后端 未结 4 1556
刺人心
刺人心 2021-01-11 11:30

I\'m trying to pass a string of the format below as the body of a http post request.

param1=PARAM1¶m2=PARAM2¶m3=PARAM3

But

4条回答
  •  春和景丽
    2021-01-11 12:14

    If you have a serialized class (like a HashMap) in the request body and you want to prevent encoding that (like in vezikon's and my problem), you can create a custom Gson with disabled escaping using:

    Gson gson = new GsonBuilder().disableHtmlEscaping().create();
    

    Pass this converter to your rest adapter:

    yourRestAdapter  = new RestAdapter.Builder()
        .setEndpoint(.....)
        .setClient(.....)
        .setConverter(new GsonConverter(gson))
        .build();
    

    This way the "=" characters in the post body stay intact while submitting.

提交回复
热议问题