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 Answer 1

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.

6
  • So the return res.getBody(); is what will redirect me to the success HTML body they send back? Commented Feb 25, 2016 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
    Commented Feb 25, 2016 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? Commented Feb 25, 2016 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
    Commented Feb 26, 2016 at 9:33
  • @KeithC have a similar problem and am getting a 302. What should I do?
    – Tyler Zika
    Commented Sep 12, 2016 at 17:52

You must log in to answer this question.

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