0

I'm using ngrok in order to tunnel localhost and check my REST request from Salesforce. However, when I send POST request I get error 405 - method not allowed. Below there is my code:

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

    req.setEndpoint('http://xxxxxxxx.ngrok.io/');
    req.setMethod('POST');
    req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
    req.setHeader('Content-Type', 'application/json');
    req.setBody(body);
    req.setCompressed(true); // otherwise we hit a limit of 32000

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

Is there something wrong with my code or is it ngrok configuration? I added this URL to remote site settings and the structure of JSON is correct. Variable body of type String is passed to the function which is the above code snippet.

  • are you sure you have the appropriate endpoint? this doenst look like something salesforce related. seems liek your question would be better ssuited for stackoverflow – glls Aug 19 '18 at 20:01
  • Endpoint is ok. It might be something with ngrok configuration. – rmatusiak Aug 19 '18 at 20:03
  • most likely, based on the server response – glls Aug 19 '18 at 20:07
  • Are you 100% your local server is accepting POST requests? I've never encountered any issues with ngrok like that, and you Salesforce code looks correct. – Matt Lacey Aug 20 '18 at 0:03
  • @MattLacey actually on ngrok inspect in headers section I see that under Allow there is not POST request. So the question now is how can I test my POST request using ngrok or any other tool that tunnels localhost? – rmatusiak Aug 20 '18 at 7:28
0

As it turned out the issue was with IIS configuration which I was using. It indeed didn't allow POST request. My above code is working correctly and now ngrok returns status 200. Thanks @MattLacey

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.