3

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?

gernberg
  • 2,587
  • 17
  • 21
Terry
  • 31
  • 2
  • 1
    Very that both the browser and your software are sending the same thing - see `wireshark` for a protocol snooper that will show you exactly what's being sent. (Or look at the log for your webserver) – KevinDTimm Jul 08 '15 at 19:55
  • http://stackoverflow.com/help/how-to-ask – Tech Savant Jul 08 '15 at 20:02
  • I'd recommend fiddler over WireShark if you are using a modern web-browser. http://www.telerik.com/fiddler – NTDLS Jul 08 '15 at 20:03

1 Answers1

3

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);
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770