我在wordpress中有这个请求,
$url = $this->apiUrl . '/' . $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json',
'X-Client: PHP ' . phpversion()
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERPWD, ":" . $this->apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
switch ($httpVerb) {
case 'post':
curl_setopt($ch, CURLOPT_POST, true);
if ($data) {
$encoded = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded);
}
break;
}
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo json_encode(curl_getinfo($ch));
curl_close($ch);
这是回复
{"url":"https:\/\/api.paylike.io\/cards\/5a05ba1d752c916c2607c5fb","content_type":null,"http_code":400,"header_size":435,"request_size":242,"filetime":-1,"ssl_verify_result":0,"redirect_count":0,"total_time":0.395293,"namelookup_time":0.01238,"connect_time":0.01387,"pretransfer_time":0.031095,"size_upload":0,"size_download":0,"speed_download":0,"speed_upload":0,"download_content_length":-1,"upload_content_length":-1,"starttransfer_time":0.395242,"redirect_time":0,"redirect_url":"","primary_ip":"104.20.8.147","certinfo":[],"primary_port":443,"local_ip":"138.68.167.102","local_port":45414}
链接没问题,但我不知道为什么会出现400错误,尝试访问该页面并看到它正常工作: https://api.paylike.io/cards/5a05ba1d752c916c2607c5fb
错误在哪里,wordpress有一些限制吗?我在wordpress之外尝试了这个代码,它的工作原理。我也试过spootify我的卷曲,但没有结果......
答案 0 :(得分:0)
首先检查系统或服务器中是否启用了卷曲。您可以使用包含此代码的简单页面进行检查。
的phpinfo();
如果启用了curl,它将显示在那里。如果未启用则启用它。
接下来检查卷曲错误并清除它。只需在curl_exec($ ch);
之后添加此代码即可'错误详情:' 。 curl_error($ CH); 它会显示错误。