You need to sign in to do that
Don't have an account?
Abdul Patel
Setting sessionId in Http Request Header
I am doing a POST call to external rest resource. The authorization is 2 step process and I need to pass the JSESSIONID in the second call which is received in first call.
With the POSTMAN, it works fine. Not sure why Apex is giving me 302 as the response status code. Can someone please help what is wrong in my code?
Body-
Header -
Below is my code for Http Request -
HttpRequest req1 = new HttpRequest();
String body = 'username=' + username + '&password=' + password + '&_csrf=' + csrf_token;
req1.setEndpoint('https://onlinehearing-backend.cloudapi-dev.sivantos.com/admin/login');
req1.setMethod('POST');
req1.setBody(body);
req1.setHeader('Cookie', sessionIdString); // sessionIdString is sessionId in format - JSESSIONID=69C4096F47BB59594D5D6C45A20A166C
//req1.setHeader('Authorization', 'Bearer '+sessionId);
Http http1 = new Http();
HTTPResponse resp = http1.send(req1);
System.debug('resp>>' + resp);
With the POSTMAN, it works fine. Not sure why Apex is giving me 302 as the response status code. Can someone please help what is wrong in my code?
Body-
Header -
Below is my code for Http Request -
HttpRequest req1 = new HttpRequest();
String body = 'username=' + username + '&password=' + password + '&_csrf=' + csrf_token;
req1.setEndpoint('https://onlinehearing-backend.cloudapi-dev.sivantos.com/admin/login');
req1.setMethod('POST');
req1.setBody(body);
req1.setHeader('Cookie', sessionIdString); // sessionIdString is sessionId in format - JSESSIONID=69C4096F47BB59594D5D6C45A20A166C
//req1.setHeader('Authorization', 'Bearer '+sessionId);
Http http1 = new Http();
HTTPResponse resp = http1.send(req1);
System.debug('resp>>' + resp);
Sometimes you need to send body along with url so try something like
Thanks
Ramesh