相关疑难解决方法(0)

使用HTTP基本身份验证从PHP发出FORM POST请求

我希望这是一个相对直接的事情,而且我的谷歌技能在这个场合让我失望了.我有一个BASIC身份验证保护资源,我想让PHP执行POST HTTP请求.

我已经尝试将身份验证:基本(加密的u/p数据)注入到看起来不起作用的标题中 - 所以我想知道,Greyskull的功能是否可以表示StackOverflow提供任何指导.

$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);
}
Run Code Online (Sandbox Code Playgroud)

php post basic-authentication

10
推荐指数
1
解决办法
9485
查看次数

标签 统计

basic-authentication ×1

php ×1

post ×1