Java 使用Rest-Assured的HTTP POST请求(示例)
下面的POST方法可用于使用Java在Rest Assured中运行HTTP POST请求 最好使用GSON依赖Java 使用Rest-Assured的HTTP POST请求(示例),java,rest,post,rest-assured,rest-assured-jsonpath,Java,Rest,Post,Rest Assured,Rest Assured Jsonpath,下面的POST方法可用于使用Java在Rest Assured中运行HTTP POST请求 最好使用GSON依赖 { RestAssured.baseURI = API_URL; RequestSpecification request = RestAssured.given(); request.header("Key1", "Value1"); request.header("Key2", ""+Value2+""); //If value is gett
{
RestAssured.baseURI = API_URL;
RequestSpecification request = RestAssured.given();
request.header("Key1", "Value1");
request.header("Key2", ""+Value2+""); //If value is getting capture from other variable
JSONObject requestParams = new JSONObject();
requestParams.put("Payload Key1", "Payload Value1");
requestParams.put("Payload Key2", "Payload Value2");
request.body(requestParams.toString());
Response response = request.post(""); //last word of URL
int StatusCode = response.getStatusCode(); //Get Status Code
System.out.println("Status code : " + StatusCode);
System.out.println("Response body: " + response.body().asString()); //Get Response Body
}
如果您使用Rest-Assured进行API测试,则可以在Rest-Assured-Java中使用此代码进行POST请求。您必须将contentType指定为“application/json”,并在post方法中传递端点 如果您使用Rest-Assured进行API测试。您必须将contentType指定为“application/json”,并在post方法中传递端点 那么你的问题是什么?:)那么你的问题是什么?:)