RestAssured

发送json请求:

    RequestSpecification request = RestAssured.given().header("Content-Type", "application/json");
    JSONObject requestParams = new JSONObject();
    JSONObject childObject1= new JSONObject();
    JSONObject childObject2 = new JSONObject();
    requestParams.put("contactClass", "ZWSS"); 
    requestParams.put("contactActivity", "0039");
    requestParams.put("contractAccountNumber", "210024144291");
    requestParams.put("text", "Please rate the overall ease of using the website to initiate or make your service request");
    requestParams.put("contactType", "Z1");
    requestParams.put("contactDirection", "1");

    childObject1.put("question", "0001");
    childObject1.put("answer", "01");
    childObject1.put("question", "0002");
    childObject1.put("answer", "02");

    JSONArray jsonArray = new JSONArray();

    jsonArray.put(childObject1);
    jsonArray.put(childObject2);
    requestParams.put("addInfo", jsonArray);

    request.body(requestParams.toString());
    Response response = request.post("https://api-dev.adp.com/api/*/*/*");

Reference

https://github.com/RookieTester/rest-assured-doc/blob/master/2016-12-12-%E3%80%90%E6%8E%A5%E5%8F%A3%E6%B5%8B%E8%AF%95%E3%80%91rest-assured%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8C%E4%B8%AD%E6%96%87%E7%89%88.markdown#JSON(%E4%BD%BF%E7%94%A8JsonPath)

java api

http://static.javadoc.io/io.rest-assured/rest-assured/3.0.1/index.html

猜你喜欢

转载自www.cnblogs.com/liehen2046/p/11689276.html