我是邮递员,我输入 URL、POST 方法、标头(键 - x-api-key 和值)、正文(listId 和值)并通过发送请求获得 200 成功响应。
但是使用maven项目,java语言,放心,我得到了-
响应状态码:500 & 响应正文:由于发生内部服务器错误,页面无法显示。
这是我的代码-
import org.testng.Assert;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.http.Method;
import io.restassured.response.Response;
import io.restassured.response.ResponseBody;
import io.restassured.specification.RequestSpecification;
import static io.restassured.RestAssured.given;
public class TC001_CacheStatus {
@Test
public void CacheStatusCheck() throws IOException {
// Set base URI of the API
String baseUrl = "https://url.here";
// Define headers
String apiKey = "x-api-key";
String apiValue = "value_here";
// Define form data
String formDataKey = "listId";
String listId = "65cd9b8f";
// Send POST request with headers and form data
Response response = RestAssured.given()
.baseUri(baseUrl)
.header("x-api-key", apiKey)
.multiPart("listId", listId)
.contentType("multipart/form-data")
.post("/endpoint")
.andReturn();
// Print response
System.out.println("Response status code: " + response.getStatusCode());
System.out.println("Response body: " + response.getBody().asString());
}
}
我该如何解决这个问题?请帮忙。
尝试“response.then().log().ifValidationFails()”来检查后查询是否正确。