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

What’s the difference between Einstein Article Recommendations and Suggested Articles?

How Does Einstein Article Recommendations Work? Einstein Article Recommendations helps support agents resolve customer cases efficiently by ...