我需要带fsockopen的手。 我需要通过代理进行Whois(Curl不适合某些Whois服务器,因此我无法使用它)
我有2个运行良好的代码,第一个使用sockopen连接到Whois服务器。 第二个通过代理调用站点。 但是我不能将两者混为一谈,但仍然收到响应“ HTTP / 1,400 Bad Request Server”。
此代码仅适用于调用Whois服务器
<?PHP
$fp = fsockopen("whois.nic.uk", 43, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />\n";
} else {
echo "<h1>Connected To The WHOIS Server.</h1>\n\n";
}
fwrite($fp, "madeupdomain.co.uk\r\n");
while (!feof($fp)) {
$contents .= fread($fp, 8192);
}
fclose($fp);
var_dump($contents);
<?PHP
function connect_to_http_proxy($host, $port, $destination) {
$fp = fsockopen($host, $port, $errno, $errstr);
if ($errno == 0) {
$connect = "CONNECT $destination HTTP/1.1\r\n\r\n";
fwrite($fp, $connect);
$rsp = fread($fp, 1024);
if (preg_match('/^HTTP\/\d\.\d 200/', $rsp) == 1) {
return $fp;
}
echo "Request denied, $rsp\n";
return false;
}
echo "Connection failed, $errno, $errstr\n";
return false;
}
$proxy = "1.2.3.4"; //Obviously it's not my proxy's ip.
$port = 12345; /it's not my proxy's ip.
$destination="ipinfo.io:80";
$fp = connect_to_http_proxy($proxy, $port, $destination);
if ($fp) {
fwrite($fp, "GET /?format=json HTTP/1.1\r\nHost: $destination\r\n\r\n");
echo fread($fp, 1024);
fclose($fp);
}
您能帮我使用代理通过这些代码联系Whois吗? 预先谢谢你。