Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are the <a href="http://hc.apache.org/httpcomponents-client-ga/index.html" rel="noreferrer">HttpClient 4 docs</a>, that is what Android is using (4, not 3, as of 1.0->2.x). The docs are hard to find (thanks Apache ;)) because HttpClient is now part of HttpComponents (and if you just look for HttpClient you will normally end up at the 3.x stuff). </p> <p>Also, if you do any number of requests you do not want to create the client over and over again. Rather, as the <a href="http://hc.apache.org/httpcomponents-client/tutorial/html/connmgmt.html#d4e604" rel="noreferrer">tutorials for HttpClient note</a>, create the client once and keep it around. From there use the <a href="http://hc.apache.org/httpcomponents-client/httpclient/apidocs/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.html" rel="noreferrer">ThreadSafeConnectionManager</a>. </p> <p>I use a helper class, for example something like <a href="http://code.google.com/p/and-bookworm/source/browse/trunk/src/com/totsp/bookworm/data/HttpHelper.java" rel="noreferrer">HttpHelper</a> (which is still a moving target - I plan to move this to it's own Android util project at some point, and support binary data, haven't gotten there yet), to help with this. The helper class creates the client, and has convenience wrapper methods for get/post/etc. Anywhere you USE this class from an <a href="http://developer.android.com/reference/android/app/Activity.html" rel="noreferrer">Activity</a>, you should create an internal inner <a href="http://developer.android.com/reference/android/os/AsyncTask.html" rel="noreferrer">AsyncTask</a> (so that you do not block the UI Thread while making the request), for example:</p> <pre><code> private class GetBookDataTask extends AsyncTask&lt;String, Void, Void&gt; { private ProgressDialog dialog = new ProgressDialog(BookScanResult.this); private String response; private HttpHelper httpHelper = new HttpHelper(); // can use UI thread here protected void onPreExecute() { dialog.setMessage("Retrieving HTTP data.."); dialog.show(); } // automatically done on worker thread (separate from UI thread) protected Void doInBackground(String... urls) { response = httpHelper.performGet(urls[0]); // use the response here if need be, parse XML or JSON, etc return null; } // can use UI thread here protected void onPostExecute(Void unused) { dialog.dismiss(); if (response != null) { // use the response back on the UI thread here outputTextView.setText(response); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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