What is the best way to make an HTTP request on Android?

1

I am using DefaultHttpClient to make requests in json from a Webservice, however this function is deprecated, what is the best alternative for creating a client for Webservice?

    
asked by anonymous 11.05.2015 / 21:38

1 answer

2

Utlize HttpClient. See the example below:

package com.hostingcompass.web.controller;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;

public class WebCrawler {

    public static void main(String[] args) throws Exception {

        HttpClient client = HttpClientBuilder.create().build();
        HttpGet request = new HttpGet("http://mkyong.com");
        HttpResponse response = client.execute(request);
        //...

    }

}

You do not need to close the connection.

    
11.05.2015 / 23:31