我正在执行 ZOMATO API 的 GET 请求,POSTMAN 工具返回成功响应,但是当我尝试使用 Eclipse 时,它返回以下消息:403 Error Invalid API Key
在 POSTMAN 和 Eclipse 中使用的 API 密钥是相同的,已经过双重检查。
eclipse代码如下:
public class exampleTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
RestAssured.baseURI = "https://developers.zomato.com";
Response res = given().
param("user-key", <api_key>).
when().
get("/api/v2.1/categories").
then().assertThat().statusCode(400).and().contentType(ContentType.JSON).extract().response();
在 POSTMAN 工具中,我在标头中传递密钥,而不是 URL 和响应是成功的,如下所示:
{
"categories": [
{
"categories": {
"id": 1,
"name": "Delivery"
}
},
{
"categories": {
"id": 2,
"name": "Dine-out"
}
},
{
"categories": {
"id": 3,
"name": "Nightlife"
}
},
{
"categories": {
"id": 4,
"name": "Catching-up"
}
},
{
"categories": {
"id": 5,
"name": "Takeaway"
}
},
{
"categories": {
"id": 6,
"name": "Cafes"
}
},
{
"categories": {
"id": 7,
"name": "Daily Menus"
}
},
{
"categories": {
"id": 8,
"name": "Breakfast"
}
},
{
"categories": {
"id": 9,
"name": "Lunch"
}
},
{
"categories": {
"id": 10,
"name": "Dinner"
}
},
{
"categories": {
"id": 11,
"name": "Pubs & Bars"
}
},
{
"categories": {
"id": 13,
"name": "Pocket Friendly Delivery"
}
},
{
"categories": {
"id": 14,
"name": "Clubs & Lounges"
}
}
]
}