How to encode space as in UrlEncodedFormEntity while executing apache HttpPost?

后端 未结 2 862
北荒
北荒 2021-01-01 06:24

The web serive i am hitting requires the parameters as URLEncodedFormEntity. I am unable to change space to %20 as per requirement of the web service, instead space is conve

2条回答
  •  温柔的废话
    2021-01-01 06:52

    The UrlEncodedFormEntity is basically a StringEntity with a custom constructor, you don't actually have to use it in order to create a usuable entity.

    String entityValue = URLEncodedUtils.format(parameters, HTTP.UTF_8);
    // Do your replacement here in entityValue
    StringEntity entity = new StringEntity(entityValue, HTTP.UTF_8);
    entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
    // And now do your posting of this entity
    

提交回复
热议问题