【问题标题】:Unable to execute REST Post request- uisng REST Assured无法执行 REST Post 请求 - 使用 REST Assured
【发布时间】:2016-03-29 11:38:54
【问题描述】:

我无法使用 REST 保证执行我们的 REST 发布 URL。我收到状态 404 错误。我们的 REST url 不需要任何身份验证、正文等。相同的 url 在 POSTMAN、RESTEasy 中工作正常。我尝试了所有四种组合以获得响应

@Test 
public void httpPost() throws JSONException,InterruptedException { 
//Initializing Rest API's URL 
String APIUrl = "http://xyz:8080/jbpm-console/rest/runtime/317002:31702Project:0.0.5-SNAPSHOT/process/317002Project.ScriptTask/start?superUser=cw-user"; 
RequestSpecBuilder builder = new RequestSpecBuilder(); 
builder.setContentType("application/json;charset=UTF-8"); 
RequestSpecification requestSpec = builder.build(); 

//Response response = given().spec(requestSpec).when().post(APIUrl);
//Response response= given().contentType("application/json").when().post(APIUrl);
Response response = given().authentication().preemptive().basic("", "").spec(requestSpec).when().post(APIUrl); 
//Response response= expect().contentType("application/json;charset=UTF-8").statusCode(200).when().post(APIUrl);

JSONObject JSONResponseBody = new JSONObject(response.body().asString()); 
System.out.println(JSONResponseBody);
}

【问题讨论】:

    标签: web-services rest rest-assured


    【解决方案1】:
    URL file = Resources.getResource("ModyNewFieldsReq.json");
    
    String myRequest = Resources.toString(file,Charsets.UTF_8);
    
            Response fieldResponse =  given ()
               .header("Authorization", AuthrztionValue)
               .header("X-App-Client-Id", XappClintIDvalue)
               .contentType("application/vnd.api+json")
               .body(myRequest).with()
    
             .when()
               .post(dataPostUrl)    
    
            .then()
               .assertThat()
               .log().ifError()
               .statusCode(200)
               .extract().response();
    
          Assert.assertFalse(fieldResponse.asString().contains("isError"));
    

    【讨论】:

    • 如果您在答案中包含描述,通常会更好地接收和更容易理解答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    • 2019-06-13
    • 1970-01-01
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    相关资源
    最近更新 更多