如果我在终端中运行它(当然使用我的真实 api ID)它工作正常。
curl -u "MYAPIID":"footastic" "https://myaccountid.wufoo.com/api/v3/forms.json"
我正在尝试使用以下方法在本地服务器(localhost)上的 PHP 中获得相同的结果:
$curl = curl_init('https://myaccountid.wufoo.com/api/v3/forms.json');
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Wufoo Form Getter');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_USERPWD, 'MYAPIID:footastic');
$response = curl_exec($curl);
$resultStatus = curl_getinfo($curl);
if ($resultStatus['http_code'] == 200) {
$result = json_decode($response, true);
} else {
$result = 'Call Failed ' . print_r($resultStatus, true);
}
echo "<pre>";
print_r($result);
echo "</pre>";
它总是返回带有以下数据的“呼叫失败”结果:
Call Failed Array
(
[url] => https://myaccountid.wufoo.com/api/v3/forms.json
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 1
[redirect_count] => 0
[total_time] => 0.216174
[namelookup_time] => 4.1E-5
[connect_time] => 0.215999
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 75.98.93.66
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 192.168.0.9
[local_port] => 54355
)
为什么它在终端中可以正常工作,但在 PHP 中却不行?知道如何让它工作吗?