我正在尝试使用以下代码上传图片:
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(
"http://konsole-data.de/uploadtest/upload.php");
MultipartEntity multiPart = new MultipartEntity();
multiPart.addPart("picture", new FileBody(new File(path)));
httpPost.setEntity(multiPart);
try {
HttpResponse res = httpClient.execute(httpPost);
Toast.makeText(getApplicationContext(),res.toString(),
Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
path 是一个字符串,用于标识图像,如 /mnt/sdcard/DCIM/12712.jpg 连接有效,但没有图像上传到服务器,您可以在此处查看调试文件:http: //konsole-data.de/uploadtest /data/20121214-144802-.dbg
做错了什么?