Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try with following approach</p> <p><strong>read and write data from URL</strong></p> <pre><code>void readAndWriteFromWeb(){ //make connection URL url = new URL("https://api.foursquare.com/v2/checkins/add/"); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setDoOutput(true); httpURLConnection.setDoInput(true); httpURLConnection.setAllowUserInteraction(true); httpURLConnection.setRequestProperty("Connection", "keep-alive"); httpURLConnection.setRequestProperty("ConnectionTimeout", "12000"); httpURLConnection.setRequestProperty("Content-Length", "" + request.length); //write data OutputStream out = httpURLConnection.getOutputStream(); out.write(request); out.flush(); //Log.e("Request URL "+url, "Request Data "+request); //read data InputStream inputStream = httpURLConnection.getInputStream(); int length = httpURLConnection.getContentLength(); //Log.e("Content Length", "" + length); int readLength = 0; int chunkSize = 1024; int readBytes = 0; byte[] data = new byte[chunkSize]; StringBuilder builder = new StringBuilder(); while((readBytes = inputStream.read(data)) != -1){ builder.append(new String(data,0,readBytes).trim()); readLength += readBytes; //Release the memory. data = null; //Check the remaining length if((length - readLength) &lt; chunkSize){ if((length - readLength) == 0){ break; } data = new byte[((length) - readLength)]; }else{ data = new byte[chunkSize]; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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