0

I'm trying to connect to a web portal via API's.

HttpRequest httpRequest = new HttpRequest();
httpRequest.setEndpoint('xxxxxxxxxxxxxxxxxxxxxxxx');
String body='account=xxxx&authenticationkey=xxxxxxxxxxx&username=Tester&id=xxxxx';

httpRequest.setBody(body);
httpRequest.setMethod('GET');
Http htt = new hTTP();

 HttpResponse httpRe = htt.send(httpRequest);
 system.debug('++++++response'+httpRe.geTbody());

 String re = httpRe.geTbody();

The 4 parameters I used are noted in the guide.But it shows up a different error.

09:26:09:229 VARIABLE_ASSIGNMENT [7]|httpRe|"System.HttpResponse[Status=OK, StatusCode=200]"|0x5eded4bb
**09:26:09:000 USER_DEBUG   <status>fail</status>**
09:26:09:000 USER_DEBUG     <items><item><code><![CDATA[-1]]></code><heading><![CDATA[Form Error]]></heading><description><![CDATA[No data received.]]></description><routine><![CDATA[]]></routine><icon><![CDATA[]]></icon><priority><![CDATA[]]></priority></item></items>

What I'm missing ?Any modification needed?

1
  • 5
    Your callout appears to have worked...
    – Adrian Larson
    Commented Mar 28, 2018 at 13:35

2 Answers 2

3

It's quite likely that the method is wrong. You wouldn't normally expect to see a body in a GET method. See:

https://www.rfc-editor.org/rfc/rfc2616#section-4.3

[...] if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request.

And the definition of GET says that it is defined by the URI, not the body:

https://www.rfc-editor.org/rfc/rfc2616#section-9.3

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.

So it's probably ignoring your body. I think you should probably change it to

httpRequest.setMethod('POST');

But whether or not that will work depends on the API you're contacting.

1
  • Actually, Salesforce converts a non-empty body callout to a post automatically.
    – sfdcfox
    Commented Mar 28, 2018 at 17:26
0

You are using the GET method.

Get Method should not have any body as per HTTP protocol suite. GET is used to retrive data, trying to provide data using GET will usually cause this error.

Your callout has worked, its the external server which does not support GET with body.

As @Adian Suggested you can try with POST, but in the end its not error related to SALESFORCE, you have to check the API docs of the third party you are integrating with.

SRC: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

You must log in to answer this question.

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