我正在尝试将Parse SDK实现到我的项目中。但是,当我尝试初始化客户端并发出测试请求时,我遇到了几个问题。看来ParseClient的cURL方法无法解析我的heroku服务器的URL。以下是我的代码:
<?php
define( 'PARSE_SDK_DIR', 'src/Parse/' );
require 'autoload.php';
use Parse\ParseClient as ParseClient;
use Parse\ParseObject as ParseObject;
use Parse\ParseQuery as ParseQuery;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseCloud;
$app_id = '';
$master_key = '';
$rest_key = '';
try{
ParseClient::initialize($app_id,$rest_key,$master_key);
echo "Parse Client Initialized. <br>";
ParseClient::setServerURL('https://myapp.herokuapp.com:1337','parse');
echo "Parse Client URL Set. <br>";
$query = new ParseQuery("_User");
$object = $query->get("003D6yZoyb");
echo $object->getObjectId();
}
catch (Parse\ParseException $ex){
echo "Error while sending query.<br>";
echo "Error code ".$ex->getCode().": ".$ex->getMessage()."<br>";
}
try{
$testObject = new ParseObject("TestObject");
$testObject->set("foo", "bar");
$testObject->save();
echo $testObject->getObjectId();
}
catch (Parse\ParseException $ex){
echo "Error while saving object<br>";
echo "Error code ".$ex->getCode().": ".$ex->getMessage()."<br>";
}
?>
使用此代码,我得到以下输出:
Parse Client Initialized.
Parse Client URL Set.
Error while sending query.
Error code 6: Couldn't resolve host 'myapp.herokuapp.com'
Error while saving object
Error code 6: Couldn't resolve host 'myapp.herokuapp.com'
但是,如果我将端口更改为443,则会出现另一个错误(0 - 未授权)。我知道服务器正在运行,如果我在终端上运行以下命令,它可以工作:
curl -X GET \
-H "X-Parse-Application-Id: appid" \
-H "X-Parse-Master-Key: masterkey" \
https://myapp.herokuapp.com:443/parse/classes/_User
如果有人知道我做错了什么,如果你能让我知道,我会非常感激!
谢谢!
编辑:还有一件事,当我ping我的服务器时,我得到了:
ping: cannot resolve https://myapp.herokuapp.com/: Unknown host
然而,终端的CURL仍然有效。