Use HttpURLConnection ( http://developer.android.com/reference/java/net/HttpURLConnection.html)
Developer docs clearly say that
An URLConnection for HTTP (RFC 2616) used to send and receive data
over the web. Data may be of any type and length. This class may be
used to send and receive streaming data whose length is not known in
advance.
Sample code to post a query :
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
writeStream(out); // read data from db and write it to stream
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
finally {
urlConnection.disconnect();
}
}
writeStream(OutputStream out) {
while (read all records from db) {
byte[] bytes = record.getBytes("UTF-8");
out.write(bytes);
}
}
Use the above code inside an AsycTask doInBackground method. Read all the records from database and add to to outputstream inside the function writeStream. Using this method, your string variable will only contain one record at any time.