2015-08-08 103 views
3

我正在尝试与google qpx api(对于航班)进行集成。 请求是带有JSON正文的POST。 我写道:试图连接谷歌qpx api时出现http错误500

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] [email protected]} 

任何人都可以帮助?

回答

0

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

应该是这样的:

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