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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)