我需要在我的localhost服务器上运行的php文件。我已下载MAMP并将Apache端口更改为80.我还将我的文件添加到htdocs文件夹中,当我运行服务器并转到localhost时,我可以在列表中看到我的.php文件。但是,当我点击它时,我收到以下错误:{“error”:“unauthorized”},没有别的。我使用该文件为我的ios应用程序,我需要知道我可以通过我的localhost地址访问该文件。我是非常新的PHP所以如果有人可以帮助我会非常感激。感谢。
守则:
<?php
header('Content-type:application/json');
$appID = $_POST['appID'];
$restAPI = $_POST['restAPI'];
$alert = $_POST['alert'];
$channels = str_replace(' ', '', $_POST['channels']);
$channels = explode(",",$channels);
$url = 'https://api.parse.com/1/push';
$data = json_encode(
array(
'channels' => $channels,
'type' => 'ios',
'data' => array(
'alert' => $alert,
'sound' => 'push.caf',
'badge' => 'Increment'
)
),true
);
$curl = curl_init();
$curlArray = array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_ENCODING => "gzip",
CURLOPT_HTTPHEADER => array(
'X-Parse-Application-Id: ' . $appID,
'X-Parse-REST-API-Key: ' . $restAPI,
'Content-Type: application/json',
'Content-Length: ' . strlen($data),
),
CURLOPT_URL => $url
);
curl_setopt_array($curl, $curlArray);
$response = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
echo $response;
?>