How to add Authorization Header to a Rest Request in Java
Hi,
I am newbie to SOAP UI java Api's. Could you please help me on setting Authorization Header to a Rest Request for a test suite in java.
Please find the Step:
WsdlProject wadlProject = new WsdlProject();
WsdlTestSuite testSuite = wadlProject .addNewTestSuite("Sample Test");
WsdlTestCase testCase = testSuite.addNewTestCase("Sample Test Case");
WsdlTestStep testStep = testCase.addTestStep("httprequest","Valid","requestURL","GET");
TestCaseRunner testCaseRunner = new WsdlTestCaseRunner((WsdlTestCase)testCase, null);
TestCaseRunContext testStepContext = new WsdlTestRunContext(testStep);
testStep.run(testCaseRunner, testStepContext);
I am not sure how to set the Authorization header in the above code. Could you please help
Same way it is! Here is a sample snippet for your reference,
import com.eviware.soapui.support.types.StringToStringMap def headers = new StringToStringMap() headers.put("Header1","Value 1") headers.put("Header2","Value 2") headers.put("Authorization","Basic fgfhgfdhCGDGRSGFEWRGFBGHLI") testCaseRunner.testCase.getTestStepAt(1).testRequest.setRequestHeaders(headers)
Thanks,
Samy
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others, Thanks. ↓↓↓