1

Here is my apex code

        String id = UserInfo.getUserId();
        User activeUser = [Select Email From User where id = :id limit 1];           

        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('http://clozer.3spire.at/checkUser');
        req.setMethod('POST');
        req.setBody('email='+activeUser.Email);
        req.setCompressed(true); // otherwise we hit a limit of 32000

        try {
            res = http.send(req);
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
        }

        System.debug('=============================new deal created ======================================'+res.getBody());

On the system log it's showing wrong answer.I send the same requesting using postmaster and the result is appropriate.

System Log enter image description here

Postmaster enter image description here

Why the result is displaying wrong ? Thanks in advance

1

An email address of e.g.:

abc@def.com

when URL encoded is:

abc%40def.com

so adding encoding may help:

req.setBody('email=' + EncodingUtil.urlEncode(activeUser.Email, 'UTF-8'));

as the default encoding for POST is application/x-www-form-urlencoded.

I would also try removing this as it doesn't seem relevant:

req.setCompressed(true); // otherwise we hit a limit of 32000

and perhaps the remote server doesn't accept compressed data.

0

believe you need to pass the email parameter in the url instead of passing it in the request body similar to what you are doing in postmaster.

req.setEndpoint('http://clozer.3spire.at/checkUser/email='+activeUser.Email);
req.setMethod('POST');
  • i saw some other posts that showing "how to send post request".they do it the way i do – moin khan Mar 14 '16 at 10:50

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.