Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you should not worry about setting 'content-length' header on a post if you are using the correct methods. With Post, you usually use some overloaded version of 'SetEntity($Type-stream/string/encodedArray...)' </p> <p>look at this <a href="http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java?view=markup" rel="nofollow noreferrer">source</a>( search on length) to see examples of how the API takes care of the length for you on a post.</p> <p>You should evaluate what lib you will use for http and find POST examples showing methods like 'setEntity' to set the body of the post. that way , you will not get errors related to content-length. see <a href="https://stackoverflow.com/questions/6028981/using-httpclient-and-httppost-in-android-with-post-parameters">example</a></p> <p>Sample code "HttpConnection" class - using links from my comment...</p> <p>For JSON OR Bitmap:</p> <pre><code>try { HttpResponse response = null; switch (method) { case GET: HttpGet httpGet = new HttpGet(url); response = httpClient.execute(httpGet); break; //Note on NIO - using a FileChannel and mappedByteBuffer may be NO Faster // than using std httpcore http.entity.FileEntity case POST: //TODO bmp to stream to bytearray for data entity HttpPost httpPost = new HttpPost(url); //urlends "audio OR "pic" if ( !url.contains("class") ){ ByteArrayOutputStream stream = new ByteArrayOutputStream(); //can alter belo for smaller uploads to parse .JPG , 40,strm bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); httpPost.setEntity(new ByteArrayEntity(stream.toByteArray())); }else if(data != null &amp;&amp; (url.contains("class"))){ //bug data is blank httpPost.setEntity(new StringEntity(data)); Log.d(TAG, "DATA in POST run-setup " +data); } response = httpClient.execute(httpPost); break; case PUT: HttpPut httpPut = new HttpPut(url); httpPut.setEntity(new StringEntity(data)); response = httpClient.execute(httpPut); break; case DELETE: response = httpClient.execute(new HttpDelete(url)); break; case BITMAP: response = httpClient.execute(new HttpGet(url)); processBitmapEntity(response.getEntity()); break; } if (method &lt; BITMAP) processEntity(response.getEntity()); } catch (Exception e) { handler.sendMessage(Message.obtain(handler, HttpConnection.DID_ERROR, e)); } </code></pre> <p>For XML body in Post:</p> <pre><code>try { HttpResponse response = null; switch (method) { case POST: HttpPost httpPost = new HttpPost(url); if (data != null){ System.out.println(" post data not null "); httpPost.setEntity(new StringEntity(data)); } if (entry != null){ ContentProducer cp = new ContentProducer() { public void writeTo(OutputStream outstream) throws IOException { ExtensionProfile ep = new ExtensionProfile(); ep.addDeclarations(entry); XmlWriter xmlWriter = new XmlWriter(new OutputStreamWriter(outstream, "UTF-8")); entry.generate(xmlWriter, ep); xmlWriter.flush(); } }; httpPost.setEntity(new EntityTemplate(cp)); } httpPost.addHeader("GData-Version", "2"); httpPost.addHeader("X-HTTP-Method-Override", "PATCH"); httpPost.addHeader("If-Match", "*"); httpPost.addHeader("Content-Type", "application/xml"); response = httpClient.execute(httpPost); break; } if (method &lt; BITMAP) processEntity(response.getEntity()); } catch (Exception e) { handler.sendMessage(Message.obtain(handler, HttpConnection.DID_ERROR, e)); } </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. 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