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

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.

  • You are exactly right. – Cray Kao Jul 15 '14 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.