Skip to content Skip to sidebar Skip to footer

Httpurlconnection, How To Sending Parameters Via Post?

String pathToOurFile = '/sdcard/DCIM/Camera/foto.jpg'; String urlServer = 'http://server/upload.php'; String lineEnd = '\r\n'; String twoHyphens = '--';

Solution 1:

for each parameter, where paramName=paramData:

outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes('Content-Disposition: form-data; name="paramName"' + lineEnd);
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(paramData);

Solution 2:

I found this blog useful for writing some multipart form data code: http://blog.rafaelsanches.com/2011/01/29/upload-using-multipart-post-using-httpclient-in-android/

Don't forget to change the boundary variable to match what you specify in the HttpURLConnection that you're using to send the multipart form to the server.

Post a Comment for "Httpurlconnection, How To Sending Parameters Via Post?"