1

I am trying to make a REST call with method as GET and body included . This call works fine from POSTMAN however from salesforce the call at server is received as POST call.

Can i make any change in request so that it is accepted as GET call only at server.

Below is my code.

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setHeader('Token', 'Bearer aejjxyzxyzhId0');
req.setHeader('Content-Type', 'application/json');
req.setEndpoint('https://serverurl.com/xyz/apis/abc/pqr/');
req.setBody('{"employee_id": 66781}');
req.setMethod('GET');
httpResponse res = h.send(req);
system.debug(res.getBody());

1 Answer 1

2

RFC 9110, the most recent RFC for the HTTP protocol, has this to say about request message in a GET request:

Although request message framing is independent of the method used, content received in a GET request has no generally defined semantics, cannot alter the meaning or target of the request, and might lead some implementations to reject the request and close the connection because of its potential as a request smuggling attack (Section 11.2 of [HTTP/1.1]). A client SHOULD NOT generate content in a GET request unless it is made directly to an origin server that has previously indicated, in or out of band, that such a request has a purpose and will be adequately supported. An origin server SHOULD NOT rely on private agreements to receive content, since participants in HTTP communication are often unaware of intermediaries along the request chain.

Apex enforces this specification by converting any GET with a request body into a POST. This is a security feature. Implementations should not be expecting a request message in a GET message. Some intermediaries, like proxies or firewalls, might not understand this content and drop it anyways.

You must log in to answer this question.

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