我想使用HttpPost将数据发布到我的网站。 这是我的代码
String st = "http://www.yade.cc/huli/classget/search.php";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(st);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("number", str));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params, HTTP.UTF_8);
post.setEntity(ent);
HttpResponse response = client.execute(post);
String retSrc = EntityUtils.toString(response.getEntity(),"utf-8");
但结果是:
406不可接受 所请求资源/huli/classget/search.php的适当表示可以 在这台服务器上找不到 此外,尝试使用ErrorDocument时遇到404 Not Found错误 处理请求。
当我将用户代理数据添加到mycode中时,它可以正常工作。
post.setHeader("User-Agent", "Chrome/28.0.1500.95");
但结果是这样的 口口口口口口导致口口口口
口意味着我无法看到的char,我不知道它是什么。
我尝试使用php做同样的事情,结果完全没问题,没有出现任何奇怪的事。
如何解决这个问题?