错误HTTP/1.0 405方法不允许

Roz*_*ozy 9 android http-status-code-405

我想做一个Htttp连接这是我的代码

try
{
HttpClient client = new DefaultHttpClient();
HttpPost httpMethod = new HttpPost("http://www.google.co.in/");
String requestBody = "some text";
HttpMethod.setEntity(new StringEntity(requestBody));
HttpResponse response = client.execute(httpMethod);
textView.setText(response.getStatusLine().toString());
}
Run Code Online (Sandbox Code Playgroud)

但我无法得到"HTTP/1.0 405方法不允许"错误,我将感谢你的帮助

Ste*_*tez 19

这意味着请求的URL不接受POST方法.再试一次GET.


Mat*_*nen 3

也许您应该尝试使用接受 POST 请求的服务器。您的代码可能没有任何问题,Google 的首页只是不执行 POST。

我能想到的一个可以使用的服务器的简单示例是JSFiddle 的 echo 功能。我确信他们不会介意。