我正在尝试测试我正在使用放心学习的一项小型休息服务。我听了这个人的视频的建议:https://www.youtube.com/watch?v=yDdBOspPp_c

但是在意识到帖子的时候说:未能解析json文档
但是,数据将保留在数据库中。我该怎么办?

@SuppressWarnings("unchecked")
    @Test
    public void deveInserirUmProduto() {

        // Specify base URI
        RestAssured.baseURI = "http://localhost:8080/ProjetoJersey/api/produto";

        // Request Object
        RequestSpecification httpRequest = RestAssured.given();

        //Request playload sending along with post request
        JSONObject requestParams = new JSONObject();

        requestParams.put("nome", "MacBook PRO");
        requestParams.put("tipoProduto", "INFORMATICA");
        requestParams.put("valor", 26000.00);
        requestParams.put("cor", "Cinza Espacial");
        requestParams.put("especificacoes", "Top de linha");

        httpRequest.header("Content-type", "application/json");

        httpRequest.body(requestParams.toJSONString());

        // Response Object
        Response response = httpRequest.request(Method.POST, "/");

        // Print response in console window
        String responseBody = response.getBody().asString();
        System.out.println("Response Body is: " + responseBody);

        // Status code validation
        int statusCode = response.getStatusCode();
        System.out.println("Status code is: " + statusCode);
        Assert.assertEquals(statusCode, 201);

        // Success code validation
        String successCode = response.jsonPath().get("SuccessCode");
        Assert.assertEquals(successCode, "OPERATION_SUCCESS");

    }

最佳答案

 Response response = httpRequest.request(Method.POST, "/");


在上面的行中,您仅输入“ /”。我认为应该是“ / register”。

07-24 20:03