请建议我如何为以下代码设置安全令牌
RestAssured.baseURI =“ http://qa.bridge2capital.com”; RestAssured.port = 9099;
RequestSpecification request = RestAssured.given();
JSONObject requestParams = new JSONObject();
requestParams.put("UserName", "10111");
requestParams.put("Password", "123568");
request.header("Content-Type", "application/json");
request.body(requestParams.toString());
Response response = request.post("/entrepreneur/consolidatedEodTrigger");
int statusCode = response.getStatusCode();
Assert.assertEquals(statusCode, "200");
String successCode = response.jsonPath().get("SuccessCode");
Assert.assertEquals( "Correct Success code was returned", successCode, "OPERATION_SUCCESS");
答案 0 :(得分:2)
您可以使用以下代码来设置基本令牌:
request.header("Authorization", "Basic " + yourToken);
答案 1 :(得分:1)
According to your answer you should try
RequestSpecification request = RestAssured.given();
JSONObject requestParams = new JSONObject();
requestParams.put("UserName", "10111");
requestParams.put("Password", "123568");
request.header("Content-Type", "application/json");
request.header("Authorization", "Basic " + base64encodedToken); //This is the important line
request.body(requestParams.toString());
Response response = request.post("/entrepreneur/consolidatedEodTrigger");
int statusCode = response.getStatusCode();
Assert.assertEquals(statusCode, "200");
String successCode = response.jsonPath().get("SuccessCode");
Assert.assertEquals( "Correct Success code was returned", successCode, "OPERATION_SUCCESS");