簡體   English   中英

WebHost PHP CURL請求失敗,錯誤7

[英]WebHost PHP CURL Request Fails With Error 7

嘗試驗證ReCaptcha響應時,無法從Web主機(1and1)連接到Google的網站。 我正在使用PHP和CURL進行連接。

如果我使用相同的代碼段並在本地運行,則可以正常工作並收到預期的響應。

我對PHP和CURL不太熟悉,因此對我應該嘗試做的任何幫助將不勝感激。

代碼片段如下:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$CaptchaSecretKey="MySecretKey";
$uCaptchaR="CaptchaResponse";

$curl = curl_init();

$captcha_verify_url = "https://www.google.com/recaptcha/api/siteverify";

curl_setopt($curl, CURLOPT_URL,$captcha_verify_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, "secret=".$CaptchaSecretKey."&response=".$uCaptchaR);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,1);
curl_setopt($curl, CURLOPT_CAINFO, 'cacert.pem');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl, CURLOPT_VERBOSE, true);

$captcha_output = curl_exec ($curl);

var_dump($captcha_output);
echo nl2br("\n");
echo nl2br("\n");
var_dump(curl_getinfo($curl));
echo nl2br("\n");
echo nl2br("\n");
echo curl_errno($curl);
echo nl2br("\n");
echo nl2br("\n");
echo curl_error($curl);

curl_close ($curl);
?>

代碼返回的輸出如下:

    bool(false) 

array(26) { ["url"]=> string(47) "https://www.google.com/recaptcha/api/siteverify" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(20.375) ["namelookup_time"]=> float(1.0E-6) ["connect_time"]=> float(0) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(0) "" ["certinfo"]=> array(0) { } ["primary_port"]=> int(0) ["local_ip"]=> string(0) "" ["local_port"]=> int(0) } 

7

Failed to connect to www.google.com port 443: Timed out

謝謝。

感謝您指出正確的方向。 通過將以下行添加到CURL腳本中,已解決了該問題。

curl_setopt($curl, CURLOPT_PROXY, 'http://ntproxyus.lxa.perfora.net:3128');

希望這也會對其他人有所幫助。

謝謝

您也可以嘗試添加要引用的URL的IP地址(獲取IP地址@ https://www.site24x7.com/find-ip-address-of-web-site.html 獲取ip地址或url )在CURL函數中將設置為“您的Web服務器出站連接”(設置為允許的連接),或者可能顯示在您的cpanel中,只需啟用它即可。

對於Web服務器卷曲功能,這將解決很多ERROR 7問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM