Sending HTTP command in browser works, not when submitting using httppost
When in my browser I send the following line to the control unit, I have http://192.168.0.215/i_activate/aterm?40~00
and activated the relay.
I've tried many options:
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 HTML response "FAIL" from the block
I've tried adding 40 ~ 00 in different ways (NameValuePair etc.) and coded in different forms with no success, but I'm pretty sure the problem is there.
Any thoughts?
source to share
The problem is that the browser is sending a request GET
where the parameter is in the url itself as a query string, but you are sending the request POST
without any body data.
Use HttpGet
instead HttpPost
to send the request GET
:
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);
source to share