0
 public static HttpResponse getIntegratedInfoFromExternalService(String WebURL , String key) {
         Http h = new Http();
     HttpRequest req = new HttpRequest();
        req.setEndpoint(WebURL);
        req.setBody('key=' + EncodingUtil.urlEncode(key,'UTF-8'));
        req.setMethod('POST');
       req.setHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');       


        try{
        HttpResponse res = h.send(req);
            System.debug(res.getBody());
             return res;
        }catch(System.CalloutException e){
            System.debug('Callout Exception' + e);

             return null;
        }

If I write a Get request it works fine. However, if I write a Post request with a set body containing the key. It doesn't process the key values. If I write the Post request with the endpoint including the key but without the set body it works fine.

I want to write a Post request with a set body containing the key.

0

I am not seeing the problem with this code:

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://requestb.in/16cfwpa1');
req.setBody('key=' + EncodingUtil.urlEncode('foo','UTF-8'));
req.setMethod('POST');
HttpResponse res = h.send(req);
System.debug(res.getBody());

https://requestb.in/16cfwpa1?inspect

Are you sure key is passed correctly?

  • How do you set the page Reference for Post Request – DominicSeb Jan 22 '18 at 16:44
  • Hey @DominicSeb not sure what are you asking, but perhaps req.setBody( Page.YOURVISUALFORCEPAGENAME.getContent().toString() ); – dzh Jan 26 '18 at 1:40

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.