Search code examples
androidrestapihttp-getsabre

Making a GET call to Sabre


I am trying to make a GET call to sabre's api. I am not receiving data in my response and I am fairly new to 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;
}

I feel like I am missing just one little step somewhere.

Any help is appreciated!


Solution

  • You can try something like this:

    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.....
    

    I have something of the sort for something else.