gpt4 book ai didi

java - 尝试连接 google qpx api 时出现 Http 错误 500

转载 作者:行者123 更新时间:2023-12-03 20:20:31 25 4
gpt4 key购买 nike

我正在尝试与 google qpx api(用于航类)集成。请求是带有 JSON 正文的 POST。我写了以下内容:

    Head request = new Head();
Gson gson = new Gson();
String json = gson.toJson(request);
System.out.println(json);

HttpClient httpClient = HttpClientBuilder.create().build();
try {
HttpPost post = new HttpPost("https://www.googleapis.com/qpxExpress/v1/trips/search?key=MY_API_KEY");
StringEntity entity = new StringEntity(json);
post.setEntity(entity);
post.addHeader("content-type", "application/json");
post.addHeader("Accept","application/json");
HttpResponse response = httpClient.execute(post);
System.out.println(response);

} catch (Exception e) {
e.printStackTrace();
}

出现这个错误:

HttpResponseProxy{HTTP/1.1 500 Internal Server Error [Vary: Origin, Vary: X-Origin, Content-Type: application/json; charset=UTF-8, Date: Sat, 08 Aug 2015 06:51:58 GMT, Expires: Sat, 08 Aug 2015 06:51:58 GMT, Cache-Control: private, max-age=0, X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, X-XSS-Protection: 1; mode=block, Server: GSE, Alternate-Protocol: 443:quic,p=1, Transfer-Encoding: chunked] org.apache.http.client.entity.DecompressingEntity@4de5031f}

有人可以帮忙吗?

最佳答案

如果有人感兴趣,问题是 JSON 请求中提交的“切片”必须是列表。

应该是这样的:

 {
"request": {
"passengers": {
"kind": "qpxexpress#passengerCounts",
"adultCount": 1
},
"slice": [
{
"kind": "qpxexpress#sliceInput",
"origin": "TLV",
"destination": "JFK",
"date": "2015-09-01"
}
],
"solutions": 1
}
}

关于java - 尝试连接 google qpx api 时出现 Http 错误 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31890686/

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