String pathToOurFile = "/sdcard/DCIM/Camera/foto.jpg";
String urlServer = "http://server/upload.php";
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
.
.
.
URL url = new URL(urlServer);
connection = (HttpURLConnection) url.openConnection();
// Allow Inputs & Outputs
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
// Enable POST method
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + pathToOurFile +"\"" + lineEnd);
outputStream.writeBytes(lineEnd);
与上面的代码,我上传到服务器中的图像,而不是如何通过邮寄HttpURLConnection,如何通过post发送参数?
有谁知道传递参数字符串类型?
检查此http://stackoverflow.com/questions/2253061/secure-http-post-in-android和此http://moazzam-khan.com/blog/?tag=android-http-post链接考虑使用HttpGet和HttpPost类 – 2012-01-17 19:45:09
试试我的方式: [Android - HttpURLConnection参数从Map通过POST方法](http://stackoverflow.com/questions/33448973/android-httpurlconnection-parameters-from-mapstring- object-via-post-method) –
2015-10-31 07:01:15