본문 바로가기

PHP

HTTP 인증(Basic타입)이 걸린 URL을 fsockopen에서 여는 방법

$objSock = fsockopen(호스트, 포트, $strErrorNo, $strErrStr, 5);
if($objSock)
{
    $strHeader  = "GET http://url부분 HTTP/1.1\r\n";
    $strHeader .= "Host:호스트:포트\r\n";
    $strHeader .= "Authorization:Basic " . base64_encode("아이디:암호") . "\r\n";
    $strHeader .= "\r\n";
    fputs($objSock, $strHeader);
    $strResult = "";
    while (!feof($objSock))
    {
        $strResult .= fgets($objSock, 65535);
    }
    fclose($objSock);
... $objSock = fsockopen(호스트, 포트, $strErrorNo, $strErrStr, 5);
if($objSock)
{
    $strHeader  = "GET http://url부분 HTTP/1.1\r\n";
    $strHeader .= "Host:호스트:포트\r\n";
    $strHeader .= "Authorization:Basic " . base64_encode("아이디:암호") . "\r\n";
    $strHeader .= "\r\n";
    fputs($objSock, $strHeader);
    $strResult = "";
    while (!feof($objSock))
    {
        $strResult .= fgets($objSock, 65535);
    }
    fclose($objSock);