问题描述
我正在尝试使用附加值将图像从 android 手机上传到 php 服务器,方法是 post我的 php 文件看起来像这样
I am trying to upload image from android phone to php server with additional values,the method is post my php file look like this
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);
我的实际问题是没有发布值,所以首先如果条件为假,否则执行其他部分,即未找到值请帮帮我
my actual problem is values are not posting so first if condition get false and else section is executed that is it give value not found please help me
推荐答案
我找到了解决问题的方法.我在行字符串 res=(" .... "); 处犯了错误我没有在每个内容之后添加 ".我已经添加了它并且我的代码可以正常工作
I have found solution of my problem. I am making mistake at line string res=(" .... "); I have not adding " " after every content.I have add it and my code working properly
链接对我非常有用:http://wiki.forum.nokia.com/index.php/HTTP_Post_multipart_file_upload_in_Java_ME
谢谢楼主帮助我
这篇关于在android中发布值并将图像上传到php服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!