Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 打电话给Sabre_Android_Rest_Api_Http Get_Sabre - Fatal编程技术网

Android 打电话给Sabre

Android 打电话给Sabre,android,rest,api,http-get,sabre,Android,Rest,Api,Http Get,Sabre,我正在尝试调用sabre的api。我没有收到 我的回复中有数据,我对httpGet/post/request还相当陌生 public HttpResponse callGetMethod() { HttpResponse response = null; try { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); reques

我正在尝试调用sabre的api。我没有收到 我的回复中有数据,我对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.....

我有些别的事要做。

但我似乎无法得到我想要的东西:如果你告诉我们你想要什么,我们可能会有所帮助。什么不按预期工作?请确保在清单文件中添加internet权限。这对于新手来说是一个常见的错误。如果你能详细说明错误或异常,或者粘贴你的日志,那么我们可以进一步帮助你。我的回复中没有收到任何数据。我使用的是asynctask,但这只是内部调用的方法。如果有帮助,GET的格式应该是这样的:感谢您在这里回答一个老问题!我不在家尝试一下,但稍后我会让你知道这是否成功。这不是问题,我最近因为另一件事遇到了像你这样的人,这对我很有用: