Java HttpClient 返回“501 方法未实现”和“POST 到/不支持”
我正在使用 HttpClient 向网页提交表单,当我查看浏览器正在发送的 HTTP 标头时,它肯定会在那里发送 POST 请求。
但是,当我尝试对 HttpClient 执行相同操作时,它会返回主题中包含消息的错误页面。
HttpPost httpost = (HttpPost) prepareRequest(new HttpPost(targetURL));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpClient.execute(httpost);
HttpEntity entity = response.getEntity();
content = EntityUtils.toString(entity);
EntityUtils.consume(entity);
I am using HttpClient
to submit a form to a webpage and when I look at HTTP header which browser is sending it is definitely sending POST request there.
But when I try to do the same with HttpClient
it returnes error page with the message in the subject.
HttpPost httpost = (HttpPost) prepareRequest(new HttpPost(targetURL));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpClient.execute(httpost);
HttpEntity entity = response.getEntity();
content = EntityUtils.toString(entity);
EntityUtils.consume(entity);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
501 还可能意味着您的内容类型对于某些网络服务器设置不正确。
如果您不想处理这个低级 API,这将是 Resty 中 x-www-form-urlencoded POST 所需的代码。
免责声明:我是 Resty 的作者。
501 could also mean that your Content type is not set correctly for some web-servers.
If you don't want to deal with this low-level API, this would be the code needed in Resty for a x-www-form-urlencoded POST.
Disclaimer: I'm the author of Resty.