When you are writing REST web service tests, you can use the following code to set the HTTP headers:
var headers = SeS('RestHeaderTest1_Get_Session').GetRequestHeaders();
SeS('RestHeaderTest1_Get_Session').SetRequestHeaders([{'Name': 'Content-Type', 'Value': 'application/json'}]);
headers = SeS('RestHeaderTest1_Get_Session').GetRequestHeaders();
Tester.Message(headers[0].Value);
If you would like to change thee headers (e.g. in this case to switch the Content-Type from JSON to XML, you might try the following:
//Set headers to XML - does not work
SeS('RestHeaderTest1_Get_Session').SetRequestHeaders([{'Name': 'Content-Type', 'Value': 'application/xml'}]);
headers = SeS('RestHeaderTest1_Get_Session').GetRequestHeaders();
Tester.Message(headers[0].Value);
However that does not work, you instead should use the following:
//Set headers to XML - does work
headers[0].Value = 'application/xml';
headers = SeS('RestHeaderTest1_Get_Session').GetRequestHeaders();
Tester.Message(headers[0].Value);
Another option that we recommend is using the new global Session object that was introduced in Rapise 5.0:
//Set original header
Session.SetRequestHeaders(...)
SeS('RestHeaderTest1_Get_Session').DoSomething(...)
//Set new headers
Session.SetRequestHeaders(...)
SeS('RestHeaderTest1_Get_Session').DoSomethingWithNewHeaders(...)