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

Best Practices for Building Prompt Templates

 Hi, The following best practices should be considered when building prompt templates: Make sure that your prompt templates are concise and ...