0

我需要将参数编码为我打算发布到网站的 ISOLatin。我正在使用 org.apache.http。图书馆。我的代码如下所示:

HttpClient client = new DefaultHttpClient();

HttpPost post = new HttpPost("www.foobar.bar");
post.setHeader("Content-Type", "application/x-www-form-urlencoded");           
HttpParams params = new BasicHttpParams();

params.setParameter("action", "find");
params.setParameter("what", "somebody");

post.setParams(params);

HttpResponse response2 = httpClient.execute(post);

谢谢!

4

1 回答 1

0

您设置的参数错误。这是一个例子,

       PostMethod method = new PostMethod(url);
       method.addParameters("action", "find");
       method.addParameters("what", "somebody");

       int status = httpClient.executeMethod(method);
       byte[] bytes = method.getResponseBody();
       response = new String(bytes, "iso-8859-1");
       if (status != HttpStatus.SC_OK)
             throw new IOException("Status code: " + status + " Message: "
                                        + response);

默认编码为 Latin-1。

于 2010-01-09T16:21:52.513 回答