Php 深度爬网验证卷曲响应为空?
要验证API调用,必须首先生成会话以获取令牌。然后,必须将会话令牌作为X-Auth-token头的值发送,以验证API调用 要创建会话,首先需要手动生成API密钥。这是可以在API访问页面中生成的密钥/值对。单击“生成新API密钥”时,将显示一个带有API密钥值的弹出窗口,在活动密钥表中,您可以找到API密钥ID。然后在会话路由的POST调用中通过基本身份验证发送该ID 我已经遵循了deepcrawl的Api文档,但我做错了什么 我有Php 深度爬网验证卷曲响应为空?,php,laravel,curl,Php,Laravel,Curl,要验证API调用,必须首先生成会话以获取令牌。然后,必须将会话令牌作为X-Auth-token头的值发送,以验证API调用 要创建会话,首先需要手动生成API密钥。这是可以在API访问页面中生成的密钥/值对。单击“生成新API密钥”时,将显示一个带有API密钥值的弹出窗口,在活动密钥表中,您可以找到API密钥ID。然后在会话路由的POST调用中通过基本身份验证发送该ID 我已经遵循了deepcrawl的Api文档,但我做错了什么 我有X-Auth-Token和API密钥ID我应该把它放在哪里 $
X-Auth-Token
和API密钥ID
我应该把它放在哪里
$deephead = "X-Auth-Token: asdjasiojqoieuqiouwqpofoqwojeq";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.deepcrawl.com/sessions");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $deephead);
// Get the response
$response = curl_exec($ch);
// Close cURL connection
curl_close($ch);
// Decode the response (Transform it to an Array)
$result = json_decode($response);
//debug the response
dd($result);
我甚至无法访问CURLOPT_get
因为在我的post
中,我只得到空值。有什么想法/想法我该如何解决这个问题。先谢谢你
看起来您正在尝试生成一个令牌,看起来您已经有了
要验证API调用,必须首先生成会话以获取
代币然后,您必须将会话令牌作为
用于验证API调用的X-Auth-Token头
要创建会话,首先需要手动生成API密钥。
这是可以在API访问页面中生成的密钥/值对。
单击“生成新API密钥”时,将显示一个带有
API密钥值,在活动密钥表中可以找到API
密钥ID。然后在对的POST调用中通过基本身份验证发送
会议路线
curl-X POST-u'123:abcdef'https://api.deepcrawl.com/sessions {
“令牌”:“abcdef123”、“\u user\u href”:“/users/example user”、…}
不是很清楚,但就在那里
$headers = [
'Content-Type: application/x-www-form-urlencoded',
'accept: text/html'
];
$username='yourusername';
$password='supersecret';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.deepcrawl.com/sessions");
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "root=1");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Get the response
$response = curl_exec($ch);
// Close cURL connection
curl_close($ch);
// Decode the response (Transform it to an Array)
return json_decode($response);
这将返回类似的结果
{
"token":"abcdef123",
"_user_href":"/users/example-user",
...
}
由于您已经拥有令牌,因此不需要进行ot hit会话。你可以打电话
$headers = [
'X-AUTH-TOKEN: your-api-key',
'accept: text/html'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.deepcrawl.com/system_statuses");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Get the response
$response = curl_exec($ch);
// Close cURL connection
curl_close($ch);
// Decode the response (Transform it to an Array)
return json_decode($response);
他们真的需要用户和密码吗?我试过这个命令,但同样的,我只得到空值:/你在点击哪个端点?如果您的帐户中没有数据,则不会有响应。我的帐户中有数据。我还有2个api密钥id和生成的会话令牌。6/7当前在我的帐户中处于活动状态。真奇怪