请建议我如何为以下代码设置安全令牌
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");
您可以使用以下代码设置基本令牌:
request.header("Authorization", "Basic " + yourToken);
根据您的答案,您应该尝试
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");