Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you need to use .addHeader for HttpGet, for example to transfer data in Json format:</p> <pre><code>public class Client { private String server; public Client(String server) { this.server = server; } private String getBase() { return server; } public String getBaseURI(String str) { String result = ""; try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(getBase() + str); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); result = getResult(response).toString(); httpClient.getConnectionManager().shutdown(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; } private StringBuilder getResult(HttpResponse response) throws IllegalStateException, IOException { StringBuilder result = new StringBuilder(); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())), 1024); String output; while ((output = br.readLine()) != null) result.append(output); return result; } } </code></pre> <p>I also suggest you to use timeoutConnection (until a connection is established) and timeoutSocket (timeout for waiting for data.) for more information look at: <a href="https://stackoverflow.com/questions/11479746/java-jersey-restful-webservice-requests/11479884#11479884">Java jersey RESTful webservice requests</a></p> <p>Also note that You need to implement your network connection on a separate thread for API level 11 or greater.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload