9

I want to make an Htttp Connection Here is my code

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());
}

But i m unable to and get the "HTTP/1.0 405 Method not Allowed" error I will be thankfull your help

James A Mohler
  • 10,562
  • 14
  • 41
  • 65
Rozy
  • 769
  • 3
  • 7
  • 11

2 Answers2

19

It means that the requested URL does not accept the POST method. Try again with GET.

Steven Benitez
  • 10,577
  • 3
  • 34
  • 49
3

Perhaps you should try with a server that accepts POST requests. There's probably nothing wrong with your code, Google's front page just doesn't do POST.

One quick example of a server you could use I can think of is JSFiddle's echo feature. I'm sure they won't mind.

Matti Virkkunen
  • 58,926
  • 7
  • 111
  • 152