我希望这是一件相对简单的事情,并且我的谷歌技能在这种情况下让我失望了。我有一个 BASIC 身份验证受保护的资源,我想让 PHP 对其执行 POST HTTP 请求。
我尝试将Authentication: Basic (加密的 u/p 数据)注入似乎不起作用的标头中 - 所以我想知道Greyskull的力量是否可以提供任何指导。
$req .= "&cmd=_initiate_query";
$header = "POST /someendpoint HTTP/1.1\r\n".
"Host:example.com\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"User-Agent: PHP-Code\r\n".
"Content-Length: " . strlen($req) . "\r\n".
"Connection: close\r\n\r\n";
$fp = fsockopen ('ssl://example.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$result .= fgets ($fp, 128);
}
fclose ($fp);
}