掙扎了半天,我終於設法得到驗證碼通過轉換此功能工作:阻塞fsockopen是什麼?
function _recaptcha_http_post($host, $path, $data, $port = 80) {
$req = _recaptcha_qsencode ($data);
$http_request = "POST $path HTTP/1.0\r\n";
$http_request .= "Host: $host\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
$http_request .= "Content-Length: " . strlen($req) . "\r\n";
$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
$http_request .= "\r\n";
$http_request .= $req;
$response = "";
if(false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10))) {
die ("Could not open socket");
}
fwrite($fs, $http_request);
while (!feof($fs))
$response .= fgets($fs, 1160); // One TCP-IP packet
fclose($fs);
$response = explode("\r\n\r\n", $response, 2);
return $response;
}
到:
function _recaptcha_http_post($host, $path, $data, $port = 80) {
$req = _recaptcha_qsencode ($data);
$request = curl_init("http://".$host.$path);
curl_setopt($request, CURLOPT_USERAGENT, "reCAPTCHA/PHP");
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, $req);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($request);
return $response;
}
基本上,我很感興趣,找出原因curl
作品而fsockopen
由於「無法打開套接字」而失敗。謝謝。
此外:插座支持已啓用。
stfu運算符(@)將錯誤消除。這使得很難找出問題所在。 – goat
@chris,錯誤是「php_network_getaddresses:getaddrinfo失敗:名稱或服務未知」。任何幫助? –
我的猜測會是你的$ host的值不正確。請參閱fsockopen() – goat