Post values and upload Image to php server in android(在android中发布值并将图像上传到php服务器)
问题描述
我正在尝试使用附加值将图像从 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服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在android中发布值并将图像上传到php服务器


基础教程推荐
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01