解决您的第二个问题:以编程方式提供 http auth 凭据
这只是为感兴趣的读者准备的,我认为(希望你)在这种情况下不需要这个
我将发送原始 HTTP,以便可以将其用于能够打开 tcp 套接字连接的各种客户端和语言
我的来源:基本访问身份验证
<?php
$username = 'myuser';
$password = 'mypass';
// computing authorization digest
$httpAuthDigest = base64_encode( "{$username}:{$password}" );
// connecting to the remote server
$fp = fsockopen( 'www.zappos.com', 80, $errno, $errstr, 60 );
if (!$fp) {
die( "{$errstr} ({$errno})\n" );
}
// send headers
fputs( $fp, "HEAD /womens-clothing HTTP/1.1\r\n" );
fputs( $fp, "Host: www.zappos.com\r\n" );
fputs( $fp, "Authorization: Basic {$httpAuthDigest}\r\n" );
fputs( $fp, "Connection: close\r\n" );
fputs( $fp, "\r\n" );
// receive result ( optional )
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
这返回了我所知道的最令人兴奋的响应标头 :)
HTTP/1.1 200 OK
Server: nginx/1.1.17
Content-Type: text/html; charset=utf-8
X-ZFC-Metadata: KjYIExIJCgNuaWQSAjQ1EhYKBmxheW91dBIMdGhyZWVfY29sdW1uEg8KA3pjMRIIQ2xvdGhpbmc=
X-Powered-By: Ponies!
X-Varnish-TTL: 60m
X-Varnish: 248743314 248742997
X-Cache-Hits: 4
X-Varnish-Host: varnish04.zappos.net
X-Varnish-ID: drupal
X-Core-Value: 5. Pursue Growth and Learning
X-Recruiting: If you're reading this, maybe you should be working at Zappos instead. Check out jobs.zappos.com
X-UUID: 9dc901f6-38ca-11e2-be29-00145e157f03
Cache-Control: max-age=3085
Date: Tue, 27 Nov 2012 19:50:38 GMT
Connection: close