1

Have checked the codes many times, looks all ok...

However, the remote side responds there's no value transmitted.

What's the wrong?

String mob = 'MOB';
String msg = 'MSG';

Http h = new Http();
HttpRequest req = new HttpRequest();
String url = 'http://www.w3schools.com/tags/demo_form_method_post.asp';
String bodyStr = 'fname='+mob+'&lname='+msg;

req.setEndpoint(url);
req.setMethod('POST');
req.setBody(bodyStr);
req.setCompressed(true);
HttpResponse res = h.send(req);
String retStr = res.getBody();

Reference:
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_form_method_post http://www.w3schools.com/tags/demo_form_method_post.asp

1 Answer 1

2

If you remove the following line, it works.

req.setCompressed(true);

This method is documented as...

If true, the data in the body is delivered to the endpoint in the gzip compressed format. If false, no compression format is used

My guess would be that the demo_form_method_post.asp does not support compression.

1
  • You are exactly right.
    – Cray Kao
    Jul 15, 2014 at 5:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .