[PHP-users 13615] https:// $B$KBP$7$F$N(B fsockopen$B$N;HMQJ}K!(B

Shinichi Moriuchi php-users@php.gr.jp
Fri, 28 Feb 2003 09:11:04 +0900


$B$*$O$h$&$4$6$$$^$9!#?9Fb$H$$$$$^$9!#(B

$B7oL>$,!"$b$l$F$*$j$^$7$?$N$G:FAw$5$;$FD:$-$^$9!#(B

fsockopen$B$K$D$$$F<ALd$,$"$j$^$9!#(B

[$B4D6-(B]
OS:Debian GNU/Linux
PHP-4.2.2
Apache-1.3.26

$B2<5-$N$h$&$K!"(Bhttps://$B$KBP$7$F%]!<%HHV9f$r(B443$B$K$7$F9T$C(B
$B$?>l9g(B
HTTP/1.1 400 Bad Request$B$HJV$C$F%U%!%$%k>pJs$,<hF@$G$-$^(B
$B$;$s!#(B

$B$A$J$_$K!"(Bhttp://$B$KBP$7$F%]!<%HHV9f(B80$B$G!"(Bfsockopen$B$rMxMQ(B
$B$7$F(B
$B%U%!%$%k>pJs$N<hF@$O!"LdBj$J$/F0:n$7$^$9!#(B

function http($url="https://www.xxxx.xx.xx/xxx/xx/",
$method="GET", $headers="", $post=array(""))
{
    $URL = parse_url($url);
    if (isset($URL['query'])) {
        $URL['query'] = "?".$URL['query'];
    } else {
        $URL['query'] = "";
    }
    $URL['port'] = 443;
    $request  = $method." ".$URL['path'].$URL['query']."
HTTP/1.0\r\n";
    $request .= "Host: ".$URL['host']."\r\n";
    $request .= "User-Agent: PHP/".phpversion()."\r\n";
    $request .= "Content-Type:
application/x-www-form-urlencoded\r\n";
    $request .= "\r\n";
    $fp = fsockopen($URL['host'], $URL['port'], &$errNo,
&$errStatus);
    if (!$fp) {
        echo "$B<:GT(B";
    } else {
        fputs($fp, $request);
        $response = "";
        while (!feof($fp)) {
            $response .= fgets($fp, 4096);
        }
        fclose($fp);
        $DATA = split("\r\n\r\n", $response, 2);
        echo $DATA[1];
        echo "$B@.8y(B";
    }
}

https://$B$KBP$7$F!"(Bfsockopen$B$N;HMQJ}K!$,0c$&$N$G$7$g$&$+(B
$B!)(B
$B$=$l$H$b!"%X%C%@>pJs$,0c$&$N$G$7$g$&$+!)(B

https://$B$K@\B3$7$F%U%!%$%k>pJs$r<hF@$9$kJ}K!$r$465<x$/$@(B
$B$5$$!#(B

$B59$7$/$*4j$$CW$7$^$9!#(B