如何连接在UrlEn codedFormEntity code空间,20%在执行apache的HttpPost? [英] How to encode space as %20 in UrlEncodedFormEntity while executing apache HttpPost?

查看:289
本文介绍了如何连接在UrlEn codedFormEntity code空间,20%在执行apache的HttpPost?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该网站的serive我击球需要参数URLEn codedFormEntity。我无法改变空间20%按Web服务的要求,而不是空间被转换到+。

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 converted to +.

我的code是:

HttpClient client = new DefaultHttpClient()
HttpPost post = new HttpPost(url);
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters,
            HTTP.UTF_8);
post.setEntity(entity);
HttpResponse resp = client.execute(post);

其中,参数为名单,其中,的NameValuePair> 参数。

我通读很多帖子,所有建议手册册的变化空间,以%20 emcoding后。在这里,我如何访问实体和手动更改呢? 任何帮助将AP preciated。

I read through many posts and all suggest manuall change space to %20 after emcoding. Here, how do i access the entity and change it manually? Any help will be appreciated.

推荐答案

在UrlEn codedFormEntity基本上是一个自定义的构造函数StringEntity,你实际上没有使用它,以创建一个usuable实体。

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

这篇关于如何连接在UrlEn codedFormEntity code空间,20%在执行apache的HttpPost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆