function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rajagopal AkellaRajagopal Akella 

Issue with handling POST request on an apex web service exposed through HTTP force.com site

My Salesforce @RestResource class is having three methods to handle PUT, POST, and GET. But when i am trying to invoke POST from external system, GET method is getting invoked.
When i try to invoke PUT and GET, they are getting invoked correctly. The issue is with POST response only. No idea why GET is getting invoked when i try to POST. Below is my class, and i am using POSTMAN to monitor PUT, POST, and GET responses.

This issue is exclusive when we try to attempt to POST using "http". You will not see this issue if you try to POST using "https".
We need to find a solution to this, as my current project needs an end point to POST using only "http".

Any information regarding this is greatly appreciated!

@RestResource(urlMapping='/myapi/IVAPIInterface/*')
global without sharing class REST_IVAPI {

    @HttpPost
    global static string doPost() {
        RestRequest req = RestContext.request; 
        System.debug('req is---------------------- ' +req); 
        return 'happy';
    }

    @HttpPut
    global static string doPut() {
        RestRequest req = RestContext.request; 
        System.debug('req is---------------------- ' +req); 
        return 'Put';
    }

    @HttpGet
    global static string doGet() {
        RestRequest req = RestContext.request; 
        System.debug('req is---------------------- ' +req); 
        return 'Get';
    }
}
James LoghryJames Loghry
You need to make sure your posting to HTTPS.  Salesforce redirects any http requests to https.  That's likely why you're seeing a GET invoked instead of a POST.  Please adjust your integration to use https instead of http.
Rajagopal AkellaRajagopal Akella
Hi James, thank you for posting your comment.
If that is the case, there is an option to uncheck "Require Secure Connection (HTTPS)" at the "site" settings right, what does that option do? Also, i went through the Salesforce documentation (Winter 16), and there is no where it was mentioned about this point. Is this a bug in Salesforce?
James LoghryJames Loghry
No, it is not a bug.  You need to adjust your external site to use https when connecting with Salesforce
Etienne GiraudyEtienne Giraudy
James, I repectfully disagree.  
We are talking here about exposing an Apex REST web service through force.com Sites.
  • Sites works on HTTP as much as on HTTPS.  
  • Rajagopal mentions is that among the use cases: GET, POST, PUT on HTTP or on HTTPS, there is an issue only with POST on HTTP, which get routed to the GET handler.
Sounds like a bug to me...