gpt4 book ai didi

java - 放心 解析 JSON 文档失败

转载 作者:行者123 更新时间:2023-12-02 01:52:48 24 4
gpt4 key购买 nike

我正在尝试测试我正在做的一个小型休息服务,以使用放心来学习。我听从了这个人视频的建议: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”。

关于java - 放心 解析 JSON 文档失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57417383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com