我正在尝试对sabre的api进行GET调用。我没有在响应中接收数据,而且我对httpGet/post/request相当陌生。
public HttpResponse callGetMethod() {
HttpResponse response = null;
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("https://api.sabre.com/v1/shop/flights?origin=ATL&destination=LAS&departuredate=2016-08-13&returndate=2016-08-15&limit=1&enabletagging=true"));
response = client.execute(request);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return response;
}我觉得我只错过了一小步。
任何帮助都是非常感谢的!
发布于 2017-06-14 11:07:50
你可以试试这样的东西:
string authoriazionToken = "T1RLAQILfFO0MrYdVVePW8z......";
WebRequest webRequest = WebRequest.Create(new URI("https://api.sabre.com/v1/shop/flights?origin=ATL&destination=LAS&departuredate=2016-08-13&returndate=2016-08-15&limit=1&enabletagging=true"));
webRequest.Method = "GET";
webRequest.Headers.Add("Authorization", "Bearer " + authoriazionToken);
webRequest.Headers.Add("Accept-Encoding", "gzip");
webRequest.ContentType = "application/json";
try
{
WebResponse webResp = webRequest.GetResponse();
using (var reader = new System.IO.StreamReader(webResp.GetResponseStream()))
{
//Insert parsing code here
}
}
catch.....我有其他的东西。
https://stackoverflow.com/questions/43774998
复制相似问题