Sunday 21 February 2021

Solution for System.HttpResponse[Status=Moved Temporarily, StatusCode=302]

 Hi ,

We get different different kinds of  response Status and Status codes when we do callouts .

One of the Http Response is 

System.HttpResponse[Status=Moved Temporarily, StatusCode=302]

To avoid this we have to follow the code snippet below.


System.HttpResponse[Status=Moved Temporarily, StatusCode=302]


 while (res.getStatusCode() == 302) {

            req.setEndpoint(res.getHeader('Location'));

            res = new Http().send(req);

 }

Usually when we get status code as 302 , the server will also provide the new location.  We need to extract that from the headers and request it as shown above.



No comments:

Post a Comment

How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...