【发布时间】:2019-01-23 07:05:56
【问题描述】:
几个月以来我一直在与放心合作。
在从开源 API 获取数据时,观察到当通过 Postman API 进行 GET 调用时返回 200 并接收到有效/预期的数据。
编写以下代码(使用 Rest-Assured 的 Java)从 API 获取相同的数据:
package com.type.GetFuelTypeFromAPI;
import static io.restassured.RestAssured.given;
import java.net.MalformedURLException;
import java.net.URL;
import org.testng.annotations.Test;
import io.restassured.response.Response;
public class SampleGetAPI {
@Test
public void getDetails() throws MalformedURLException {
Response response=
given()
.queryParam("cmd", "getTrims")
.queryParam("make", "Abarth")
.queryParam("year", "1955")
.queryParam("model", "207")
.when()
.get(new URL("https://carqueryapi.com/api/0.3/"));
String responseBody = response.body().asString();
System.out.println(responseBody);
}
}
代码输出为:
[TestNG] Running:
C:\Users\AaSomvanshi\AppData\Local\Temp\testng-eclipse-1657322415\testng-customsuite.xml
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /api/0.3/
on this server.<br />
</p>
<p>Additionally, a 403 Forbidden
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
PASSED: getDetails
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
有人可以指导我如何克服这个问题吗?
【问题讨论】:
标签: java wireshark rest-assured