获取的数据在Java中被发送到HttpPost PHP脚本 [英] Get Data Sent by HttpPost in Java to php Script

查看:390
本文介绍了获取的数据在Java中被发送到HttpPost PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Andr​​oid应用程序应该使用HttpPost的事情是我现在还不能接收任何数据到PHP脚本,虽然我监视我的应用程序通过网络发送数据将数据发送到PHP脚本。我用下面的PHP code来获得数据:

My android app should send data to php script using HttpPost, the thing is I still can't receive any data to the php script, although I monitored that my app is sending data through the network. I used the following php code to get data:

<?php
$raw_post = file_get_contents("php://input"); 
echo $raw_post;
?>

任何建议,以诊断问题,并确保它是否是来自我的PHP端或应用程序方面?

Any suggestions to diagnose the problem and make sure if it is from my php side or the app side?

推荐答案

假设你正在使用ENCTYPE =的multipart / form-data的上传文件,You'l必须得到在PHP文件引用:

Assuming you are uploading file using enctype="multipart/form-data", You'l have to get file reference in php:

<?php
$file=$_FILES['file_arg_name'];
$raw_post = file_get_contents($file['tmp_name']);
echo $raw_post;
?>

请注意:如果你有特殊字符,如空格打开一个URI,你需要连接code中的URI与urlen code()。看到的file_get_contents PHP文件()了解更多详情

Note: If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode(). see PHP Doc for file_get_contents() for more details

这篇关于获取的数据在Java中被发送到HttpPost PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆