发布值并将图像上传到android中的php服务器

我试图将图像从Android手机上传到带有附加值的php服务器,该方法是发布我的php文件看起来像这样

if($_POST['val1']){ if($_POST['val2']){ if($_FILE['image']){ ...... } } }else{ echo "Value not found"; } 

我正在做的

 URL url=new URL("http://www/......../myfile.php"); HttpURLConnection con=(HttpURLConnection) url.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); con.setRequestMethod("POST");//Enable http POST con.setRequestProperty("Connection", "Keep-Alive"); con.setRequestProperty("Content-Type", "multipart/form-data;boundary="+"****"); connection.setRequestProperty("uploaded_file", imagefilePath); DataOutputStream ostream = new DataOutputStream( con.getOutputStream()); String res=("Content-Disposition: form-data; name=\"val1\""+val1+"****"+ "Content-Disposition: form-data; name=\"val2\""+val2+"****" "Content-Disposition: form-data; name=\"image\";filename=\"" + imagefilePath +"\""+"****"); outputStream.writeBytes(res); 

我的实际问题是,如果条件为false,则首先不发布值,否则执行部分,即它找不到值,请帮助我

我找到了解决问题的方法。 我在线字符串res =(“….”)犯了错误; 我没有在每个内容之后添加“\ r \ n”。我已添加它并且我的代码正常工作

链接对我非常有用: http : //wiki.forum.nokia.com/index.php/HTTP_Post_multipart_file_upload_in_Java_ME

谢谢先生帮助我

这是一篇很好的文章, http://blog.sptechnolab.com/2011/03/09/android/android-upload-image-to-server/ 。 有用。