+ Start a Discussion
sfdcsushilsfdcsushil 

Setting Cookie Header in HTTP callout

Hello,

I am using below code for setting Cookie in HTTP callout , Looks like its not working. 
Is my code correct? 

HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setHeader('Cookie', 'Name=Value');

Regards,
Sushil


PrasanntaPrasannta (Salesforce Developers) 
Hi,

In order to set HTTP headers, add inputHttpHeaders_x and outputHttpHeaders_x to the stub.

Here's an example that sets input HTTP Headers:
docSample.DocSamplePort stub = new docSample.DocSamplePort();
stub.inputHttpHeaders_x = new Map<String, String>();

//Setting a basic authentication header
stub.inputHttpHeaders_x.put('Authorization', 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==');

//Setting a cookie header
stub.inputHttpHeaders_x.put('Cookie', 'name=value');

where stub is included in the apex class included in the Apex class generated from the WSDL document for calling the third-party Web service represented by the WSDL document.

You can modify the above code example as per your requirement. Hope this helps you to get the working code.
sfdcsushilsfdcsushil
Hello, Thanks for responding. But I am doing Http callout not soap callout. So there is no separate stub. How can I add cookie in http callout. Thanks.
AJAY SINGH 197AJAY SINGH 197
Is this issue fixed ? i am facing the same issue . Kindly help.