首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打电话到Sabre

打电话到Sabre
EN

Stack Overflow用户
提问于 2017-05-04 06:02:02
回答 1查看 129关注 0票数 0

我正在尝试对sabre的api进行GET调用。我没有在响应中接收数据,而且我对httpGet/post/request相当陌生。

代码语言:javascript
复制
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;
}

我觉得我只错过了一小步。

任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-14 11:07:50

你可以试试这样的东西:

代码语言:javascript
复制
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.....

我有其他的东西。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43774998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档