Send large post param in Android
How do you send a large (>5MB) post parameter (among other post parameters) in Android?
I'm currently using org.apache.h开发者_如何学运维ttp.client.methods.HttpPost
and a list of BasicNameValuePair
to send the post params.
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(someURL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("param1", "value1"));
nameValuePairs.add(new BasicNameValuePair("param2", hugeValue));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
hugeValue
is a very large string that I would like to read from an InputStream
and send as I read it. How can I do this?
CommonsWare is right. HttpUrlConnection and writing direct into the outputstream will solve your memory problem. I've used it in my own application for uploading 10 and more mb of image data.
A good example according your kind of post request is: http://www.java.happycodings.com/Other/code21.html
精彩评论