hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 韩侨 <Hanq...@Koolearn-inc.com>
Subject 答复: fail to post content including chinese word
Date Fri, 10 Mar 2006 10:06:38 GMT
It helps. thanks very much  :)

The code is as follows now : 

		PostMethod postMethod = new PostMethod(url);
		postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
		StringPart sp1 = new StringPart("subject", "我非常张含蕴", "UTF-8");
		StringPart sp2 = new StringPart("body", "放假", "UTF-8");
		StringPart sp3 = new StringPart("forumID", "39", "UTF-8");
		StringPart sp4 = new StringPart("p", "563584", "UTF-8");
		
		Part[] parts = {sp1,sp2,sp3,sp4};
		postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));

			int statusCode = httpClient.executeMethod(postMethod);

-----邮件原件-----
发件人: Roland Weber [mailto:ROLWEBER@de.ibm.com] 
发送时间: 2006年3月10日 17:30
收件人: HttpClient User Discussion
主题: Re: fail to post content including chinese word

Hi,

you've got to use a multipart request entity for posting strings
in a specific charset. You can add string parts there:

http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/methods/multipart/package-summary.html
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/methods/multipart/StringPart.html

hope that helps,
  Roland




韩侨 <Hanqiao@Koolearn-inc.com> 
10.03.2006 09:07
Please respond to
"HttpClient User Discussion"


To
<httpclient-user@jakarta.apache.org>
cc

Subject
fail to post content including chinese word






When I post the english content very smoothly, I faced problem when 
posting content including chinese word. 

NameValuePair[] data = { 

new NameValuePair("subject",  "yao on fire呵呵"),

new NameValuePair("forumID", "39"), 

};

 

The post action is successful, but “yao on fire呵呵” becomes “yao on fire 
??”

I tried several way: 

1. use: 

new NameValuePair("subject", new String(("yao on fire 哈哈
").getBytes("GBK"), "iso-8859-1")),

does not hold .

 

2. according to the doc

I insert the line as follows:

postMethod.addRequestHeader("Content-type","text/xml; 
charset=ISO-8859-1");

 

but request becomes puzzled, even resulting in failing of post action.

 

Help !!

 






---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message