我正在尝试使用 curl 连接到Marketo.com REST API。我无法从身份服务获得响应。我只收到一条错误消息
"[curl] 6: 无法解析主机 'MY_CLIENT_ENDPOINT.mktorest.com'
,但我可以打印构造的 url 并将其粘贴到浏览器地址栏中,这将提供带有 access_token 元素的预期响应。
我可以在 php 和终端中使用 curl 来访问我的 gmail 帐户,因此 curl 能够访问 https 服务。我尝试将 curl url 中的参数作为获取请求发送,并使用 curl 的 -F 选项将它们声明为发布请求
我的应用程序使用github 上提供的 dchesterton/marketo-rest-api,但我也尝试了一个简单的 php curl 请求来获取访问令牌。
private function getToken() {
$url = "$this->client_url/identity/oauth/token?grant_type=client_credentials&client_id=$this->client_id&client_secret=$this->client_secret";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$errors = curl_error($ch);
curl_close($ch);
file_put_contents($this->logDir . 'access_token_response' . date('Y-m-d') . '.txt', $url . "\n" . $response . "\n", FILE_APPEND);
if ($errors) {
file_put_contents($this->logDir . 'access_token_errors' . date('Y-m-d') . '.txt', $errors . "\n", FILE_APPEND);
}
return $response['access_token'];
}
同样,这会失败并出现相同的错误,但会生成一个格式完美的 url,我可以将其粘贴到浏览器中并获得有效的响应。我也尝试过使用 post 而不是 get ,就像我对提到的所有其他测试一样,这些已经在我的本地主机和测试服务器上进行了尝试。
谁能向我解释为什么这会失败?Marketo 是否按每个帐户阻止 curl?