在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服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

相关文档推荐

Reliable implementation of PBKDF2-HMAC-SHA256 for JAVA(PBKDF2-HMAC-SHA256 for JAVA 的可靠实现)
Correct way to sign and verify signature using bouncycastle(使用 bouncycastle 签名和验证签名的正确方法)
Creating RSA Public Key From String(从字符串创建 RSA 公钥)
Why java.security.NoSuchProviderException No such provider: BC?(为什么 java.security.NoSuchProviderException 没有这样的提供者:BC?)
Generating X509 Certificate using Bouncy Castle Java(使用 Bouncy Castle Java 生成 X509 证书)
How can I get a PublicKey object from EC public key bytes?(如何从 EC 公钥字节中获取 PublicKey 对象?)