简体   繁体   English

获取Java中HttpPost发送的数据到php脚本

[英]Get Data Sent by HttpPost in Java to php Script

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. 我的Android应用程序应该使用HttpPost将数据发送到php脚本,但是我仍然无法接收任何数据到php脚本,尽管我监视了我的应用程序正在通过网络发送数据。 I used the following php code to get data: 我使用以下php代码获取数据:

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

Any suggestions to diagnose the problem and make sure if it is from my php side or the app side? 任何建议来诊断问题,并确保它是从我的PHP方面还是从应用程序方面?

Assuming you are uploading file using enctype="multipart/form-data", You'l have to get file reference in php: 假设您使用enctype =“ multipart / form-data”上传文件,则必须在php中获取文件引用:

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

Note: If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode(). 注意:如果要使用特殊字符(例如空格)打开URI,则需要使用urlencode()对URI进行编码。 see PHP Doc for file_get_contents() for more details 有关更多详细信息,请参见PHP doc中的file_get_contents()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM