Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://developer.android.com/reference/org/apache/http/client/HttpClient.html" rel="nofollow">HttpClient</a> is the class to use and there's a <a href="http://developerlife.com/tutorials/?p=288" rel="nofollow">tutorial</a> for it. See the section <em>Using HTTP client</em>, right after the pictures.</p> <p><strong>UPDATE</strong><br> What follows is commentary on the tutorial example from <a href="http://developerlife.com/tutorials/?p=288" rel="nofollow">Developerlife.com</a>. A good thing about that example is that it demonstrates how to send various types of data by encoding one type into another. One can send any of the types used in that chain of data conversions, by starting at the point in the chain that matches the type of data to be sent:</p> <p><em>Strings</em> are put in a <em>Hashtable</em> which is written to an <em>ObjectOutputStream</em> which is backed by a <em>ByteArrayOutputStream</em> that gets converted into a ByteArray that is in turn converted into a ByteArrayEntity for transmission.</p> <p>To send just a <em>ByteArray</em>, skip all the steps that occur before the data becomes a <em>ByteArray</em>. Jump in at line 26 where a <em>ByteArray</em> is created with <code>toByteArray().</code></p> <p>For sending other types do the following(as per the example):<br> Line 26: <em>ByteArray</em>, just use it to make a <em>ByteArrayEntity</em><br> Line 26: <em>ByteArrayOutputStream</em>, convert it to a <em>ByteArray</em><br> Line 24: <em>ObjectOutputStreams</em>: create them on <em>ByteArrayOutputStreams</em><br> Line 25: <em>Objects</em>: Write <em>Strings</em>, <em>Hashtables</em>, etc to an <em>ObjectOutputStream</em>. </p> <pre><code> 1 /** this method is called in a non-"edt" thread */ 2 private void _doInBackgroundPost() { 3 Log.i(getClass().getSimpleName(), "background task - start"); 4 5 6 Hashtable&lt;String, String&gt; map = new Hashtable(); 7 map.put("uid", uid); 8 map.put("pwd", pwd); 9 10 try { 11 HttpParams params = new BasicHttpParams(); 12 13 // set params for connection... 14 HttpConnectionParams.setStaleCheckingEnabled(params, false); 15 HttpConnectionParams.setConnectionTimeout(params, NetworkConnectionTimeout_ms); 16 HttpConnectionParams.setSoTimeout(params, NetworkConnectionTimeout_ms); 17 DefaultHttpClient httpClient = new DefaultHttpClient(params); 18 19 // create post method 20 HttpPost postMethod = new HttpPost(LoginServiceUri); 21 22 // create request entity 23 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 24 ObjectOutputStream oos = new ObjectOutputStream(baos); 25 oos.writeObject(map); 26 ByteArrayEntity req_entity = new ByteArrayEntity(baos.toByteArray()); 27 req_entity.setContentType(MIMETypeConstantsIF.BINARY_TYPE); 28 </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.
 

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