Sending HTTP command in browser works, not when sent with httppost

100 Views Asked by At

When in my browser I send the following string to a control unit I have http://192.168.0.215/i_activate/aterm?40~00 and a relay is activated.

I have tried many variations of the following:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.0.215/i_activate/aterm?40~00");

// Execute HTTP Post Request            
HttpResponse response = httpclient.execute(httppost);

With an HTML response "FAIL" from the unit

I have tried adding the 40~00 in many ways (NameValuePair, etc) and encoded in different forms without success but I am sure the problem lies there.

Any thoughts?

1

There are 1 best solutions below

1
Remy Lebeau On

The problem is that the browser sends a GET request, where the parameter is in the URL itself as a query string, but you are sending a POST request without any body data.

Use HttpGet instead of HttpPost to send a GET request:

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://192.168.0.215/i_activate/aterm?40~00");

// Execute HTTP Get Request
HttpResponse response = httpclient.execute(httpget);