問題描述
我正在嘗試使用附加值將圖像從 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服務器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!