我已经准备好进行自己的测试,并且已经通过下载 apache httpclient 在 android 上完成了测试,但这对你的情况来说应该不是问题。
我在“libs”文件夹中包含了 httpclient.jar 和 httpmime.jar。
最重要的是在 multipart-message 的 mime-part 上设置 part-name。这是你的 assoc 的第一部分。php 数组。
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(
CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost(url_string);
File file = new File(file_string);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("userfile", cbFile);
httppost.setEntity(mpEntity);
System.out
.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
System.out.println(statusLine);
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
if (resEntity != null) {
resEntity.consumeContent();
}
httpclient.getConnectionManager().shutdown();
return statusLine != null ? statusLine.getStatusCode() : 0;