簡體   English   中英

我正在嘗試從php $ _GET獲取數據,然后使用rest api對其進行解析,但這會導致錯誤

[英]I am trying to get data from php $_GET then parse it using rest api, but it causes an error

我正在嘗試從php $ _GET獲取數據,然后使用rest api對其進行解析,但這會導致錯誤,因此請大家幫忙。

<?php  
$number=$_GET['name'];
$media=$_GET['media'];

$url = 'https://api.parse.com/1/classes/AppTo';  
$appId = 'ccccc';  
$restKey = 'ccccc';  
$headers = array(  
"Content-Type: application/json",  
"X-Parse-Application-Id: " . $appId,  
"X-Parse-REST-API-Key: " . $restKey  
);  

$objectData = '{"name":(json_encode($number)), "age":(json_encode($media))}';  
$rest = curl_init();  

curl_setopt($rest,CURLOPT_URL,$url);  
curl_setopt($rest,CURLOPT_POST,1);  
curl_setopt($rest,CURLOPT_POSTFIELDS,$objectData);  
curl_setopt($rest,CURLOPT_HTTPHEADER,$headers);  
curl_setopt($rest,CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($rest,CURLOPT_RETURNTRANSFER, true);  
$response = curl_exec($rest);  
echo $response;  
print_r($response);  
curl_close($rest);  
?> 

您實際上是在發布文本{"name":(json_encode($number)), "age":(json_encode($media))} 您可以改為構造json:

$objectData = json_encode(array('name' => $number, 'age' => $media));

您發布的數據更改有誤

$objectData = '{"name":(json_encode($number)), "age":(json_encode($media))}';

$objectData = json_encode(array('name' => $number, 'age' => $media));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM