+ Start a Discussion
GAURAV SETHGAURAV SETH 

Calling Webservice from Apex class, getting 302 response error

Hi,
I am calling external web services from my Apex class .
I am getting response code 302 instead of 
response.getStatusCode() == 200.

If I am adding request.setHeader() Cookie value which I copied from Postman application when hitting the same web service. It works fine.

Looks like there is some configuration missing? 
Can someone please help me in this ?
Ashima nidhiAshima nidhi
Hi @Gaurav can you please check this thread https://salesforce.stackexchange.com/questions/11126/how-do-i-handle-a-302-redirect-response-to-my-http-callout
if it helps. 
GAURAV SETHGAURAV SETH
Thanks. I checked and used it .Still getting the same error.
After creating certificate in Salesforce , Do I have to share it with external site ?

I changed my httpRequest as below giving certificate name and adding Named Credentials to end point.
where 'Curam_Application' is the Named Credential defined in Setup and 'SSCert_SFBot_IBMCuram' is the certificate name
But it also do not work. Can someone please assist, what is going wrong?


     Http http = new Http();
        HttpRequest request = new HttpRequest();
        String intake_Id = intakeId[0];
        
        String EndPoint = 'callout:Curam_Application/v1/cwa/intakes?investigation_id='+intake_Id;
        request.setEndpoint(EndPoint);
        request.setMethod('GET');
        request.setClientCertificateName('SSCert_SFBot_IBMCuram');
       
         request.setTimeout(2000);
        HttpResponse response = http.send(request);

Thanks,
Gaurav Seth