1
我正在嘗試向API發出PUT請求。該請求是成功的,如果我做了在終端如下:PHP捲曲不起作用,但終端捲曲不起作用
curl -H "Authorization: Bearer abc123" -X PUT -d "story[title]=Testing" "http://api.mavenlink.com/api/v1/stories/1.json"
這嫋嫋的工作就好了,但是當我嘗試做使用PHP與下面的代碼它它不工作:
$curlOptions = array
(
CURLOPT_URL => "https://api.mavenlink.com/api/v1/stories/1.json",
CURLOPT_HTTPHEADER => array('Authorization: Bearer abc123'),
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "story[title]=Testing"
);
$curlHandle = curl_init();
curl_setopt_array($curlHandle, $curlOptions);
$content = curl_exec($curlHandle);
if ($content === false) {
print_r(curl_error($curlHandle));
}
print_r($content);
我當我轉到頁面時打印出錯是SSL連接錯誤。我已經四處搜索並嘗試了多個捲曲選項:
CURLOPT_SSLVERSION => 3,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_CIPHER_LIST => "rsa_rc4_128_sha",
既不能解決問題。爲什麼它會在終端中工作,但如果選項相同,不會在PHP中工作?什麼是從PHP導致錯誤缺少?提前致謝!
UPDATE 基於米克爾的回答,我改變了PHP的網址爲http。這並沒有顯示錯誤,但也沒有成功。所以,我做了一個curl_getinfo去以下:
Array ([url] => https://api.mavenlink.com/api/v1/stories/1.json [content_type] => text/html [http_code] => 301 [header_size] => 237 [request_size] => 435 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 1 [total_time] => 0.216551 [namelookup_time] => 4.1E-5 [connect_time] => 0.043997 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0 [redirect_time] => 0.21663 [certinfo] => Array () [primary_ip] => 55.555.555.555 [redirect_url] =>)
因此,我增加CURLOPT_FOLLOWLOCATION => true,
在PHP代碼捲曲選項。嘗試之後,我仍然收到錯誤SSL連接錯誤
有趣。我已經嘗試在PHP中的http,它仍然沒有工作。我會再次嘗試查看結果。我會在一會兒回覆。感謝您的熱烈歡迎! – mattshull
我已根據您的建議添加了對帖子的更新。 – mattshull