对 Saber 进行 GET 调用
Making a GET call to Sabre
我正在尝试对 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;
}
我觉得我在某处少了一小步。
感谢任何帮助!
您可以尝试这样的操作:
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.....
我有一些类似的东西。
我正在尝试对 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;
}
我觉得我在某处少了一小步。
感谢任何帮助!
您可以尝试这样的操作:
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.....
我有一些类似的东西。