0

So, I've got a HTTP Post that I am doing with two parameters. I'm not receiving any sort of session ID back to help me with the URL redirect. Apparently it is more of a 'post to this' and you're in. Which, I went into Postman and was able to put in the parameters and get a Status 200 OK. However, the response was HTML.

When I hit Preview in Postman it showed me the webpage that I was needing to be redirected to, essentially. How can I do a post to redirect like this within Salesforce? Is that possible or do I have to receive a session ID/cookie back to get something like this to work?

1

If the website that you are posting to and the website it redirects to do not require any authentication then you can use the Apex HTTP Classes in a fairly straightforward way. (You will have to add the site to the Remote Site Settings too.)

Note though that while sometimes a redirect is done via a 302 status response and a location header, other techniques can be used including JavaScript embedded in a response page. While that is easy for a browser to handle, it is harder to handle in Apex code.

|improve this answer|||||
  • So the return res.getBody(); is what will redirect me to the success HTML body they send back? – David Litton Feb 25 '16 at 17:27
  • 1
    @DavidLitton The body may just be the success HTML (so you are done) or you could get a 302 response with a location header or you could get JavaScript in the response that does a redirect; you'll have to check the responses. I only mentioned redirect because you did in the question... – Keith C Feb 25 '16 at 18:00
  • I'm getting an HTML response in the body. I assume I want to display that on my page when I receive it? – David Litton Feb 25 '16 at 19:48
  • 1
    @DavidLitton Yeah you can output that content if you want to, though see the warning about escape=false in apex:outputText. – Keith C Feb 26 '16 at 9:33
  • @KeithC have a similar problem and am getting a 302. What should I do? – Tyler Zika Sep 12 '16 at 17:52

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.