我正在尝试使用 MultiPartEntity 将图像从 android 上传到 PHP 服务器,但我很难找到问题的根源,进度对话框钢铁下载没有在我的代码中提供任何响应:
public String postFunction(String s_v1, String s_v2, String s_v3)
throws ParseException, ClientProtocolException, IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(s_v1);
//required apache-mime4j-0.6, et httpmime-4.0.3
MultipartEntity mp = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mp.addPart("choix", new StringBody("2"));
boolean exists = (new File("/data/data/my.package/files/avatar.jpg")).exists();
if (!exists){
Log.i(TAG,"no file");
}
else
{
File tempImg = new File("/data/data/my.package/files/avatar.jpg");
FileBody bin = new FileBody(tempImg, "image/jpg");
mp.addPart("photo_r", bin);
}
mp.addPart("myString1", new StringBody(s_v2, Charset.forName( "UTF-8" )));
mp.addPart("myString2", new StringBody(s_v3, Charset.forName( "UTF-8" )));
httppost.setEntity(mp);
Log.i(TAG,"start ");
HttpResponse response = httpclient.execute(httppost);
Log.i(TAG,"end");
return response;
}
我不知道哪里出了问题!! 非常感谢 ;)
最佳答案
问题解决了,那是因为我的网络连接不畅,现在我尝试使用模拟器中生成的 SocketTimeoutException 来限制连接时间,但不幸的是我的手机 acer liquid 中没有!
关于php - 将图像从 android 上传到 PHP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3798823/