我正在尝试将 JSON 帖子数据从 Android 应用程序获取到 PHP Web 服务,但它无法获取.下面显示了我使用


i am trying to fetch the json post data from android app to php web service but it can't fetch. the code show below which i used

我创建了此代码以从Android应用程序获取数据。 获取 JSON 数据后,我正在解码它们,然后我获取关键变量,即图像的 Base 64 代码和ori_name变量,即图像名称。 之后,我从 Base 64 代码在服务器端创建图像文件并将文件存储在服务器中。 如果图像存储在服务器中,则 IAM 存储映像名称和图像路径在一个数据库中。当我使用 android 应用程序执行此代码时,它仅在 android 端返回 nil。这里有任何获取数据的解决方案吗?请注意,Android应用程序是由使用我创建此服务的朋友开发的。当他使用它时,他得到零值。请帮我解决这个问题。

<?php
//process client request(via URL)
header("content-Type:application/json");
$data=$_REQUEST['jdata'];//request json data
$imgdata=json_decode($data);//decode json data
$basecode=$imgdata->{'key'};//fetch base64 code of image
$imgname=$imgdata->{'ori_name'};//fetch image name
$response=get_url($basecode,$imgname);//cal function for store image at server
return deliver_response($response);
function deliver_response($status)
{
header("HTTP/1.1");
$response['status']=$status;
$json_response=json_encode($response);
return $json_response;//return json response to android app
}
function get_url($basecode,$imgnm)
{
$decoded= base64_decode($basecode);//convert base 64 code to string format
$location=$_SERVER['HTTP_HOST']."/Clients/krishinternational/MobileService/images/".$imgnm;
$output_file="../images/".$imgnm;//define output file location
$ifp = fopen($output_file, "wb"); //create file
    $rs=fwrite($ifp, $decoded); //write image in file
    if($rs!=False)//check weather file is written or not
    {
        fclose($ifp); 
        $conn =mysqli_connect('host','user','password','db_name');//creating database connection
        if ($conn->connect_error) 
        {
        die("Connection failed: " . $conn->connect_error);
        } 

        $query="insert into tblimage values('".$imgnm."','".$location."')";//query to store image path in database
        if ($conn->query($query) === TRUE) 
        {
        //echo "New record created successfully";                               
        mysqli_close($conn);
        return True;//if successfully inserted then return true
        }           
        else 
        {
        return False;//if not succeed then return false
        }
      }
        else
       {
        return False;
       }
    }
    ?>

谢谢因陀罗,我得到了 Rest 客户端的结果测试。 错误是我正在从Android应用程序请求JSON数据,但实际上我必须使用file_get_contents。

$input=file_get_contents("php://input");

谢谢因陀罗