0
我在使用fsockopen執行POST後發現我的GET請求
我發送了cookie,但沒有成功。fsockopen - POST和GET PHP
我接收HTTP/1.1 302對象移動 - >POST
我接收HTTP/1.1 302對象移動 - >GET,但我希望收到HTTP/1.1 200 OK
我的代碼:
用法: $這個 - >閱讀();
function HTTP_POST($URL, $data, $referrer="")
{
$URL_Info=parse_url($URL);
if($referrer=="")
{
$referrer=$_SERVER["SCRIPT_URI"];
}
foreach($data as $key=>$value)
{
$values[]="$key=".urlencode($value);
}
$data_string=implode("&",$values);
if(!isset($URL_Info["port"]))
{
$URL_Info["port"]=80;
}
$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
$request.="Host: ".$URL_Info["host"]."\n";
$request.="Referer: $referer\n";
$request.="Content-type: application/x-www-form-urlencoded\n";
$request.="Content-length: ".strlen($data_string)."\n";
$request.="User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/2100101 Firefox/4.0.1\n";
$request.="Connection: close\n";
$request.="\n";
$request.=$data_string."\n";
$fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
fputs($fp, $request);
while(!feof($fp))
{
$result .= fgets($fp, 128);
}
fclose($fp);
return $result;
}
function HTTP_GET($URL, $cookie, $referrer="")
{
$URL_Info = parse_url($URL);
if($referrer=="")
{
$referrer=$_SERVER["SCRIPT_URI"];
}
if(!isset($URL_Info["port"]))
{
$URL_Info["port"]=80;
}
$request.="GET ".$URL_Info["path"]." HTTP/1.1\n";
$request.="Host: ".$URL_Info["host"]."\n";
$request.="Referer: $referer\n";
$request.="User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/2100101 Firefox/4.0.1\n";
$request.="Cookie: ".$cookie."\n";
$request.="Connection: close\n";
$request.="\n";
$fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
fputs($fp, $request);
while(!feof($fp))
{
$result .= fgets($fp, 128);
}
fclose($fp);
return $result;
}
function read()
{
$headers = array();
$data = array('CNPJ' => '02340534000192', 'consulta' => 'OK', 'vazio' => '');
$html = $this->HTTP_POST('http://www.sefaz.pe.gov.br/sintegra/consulta/consulta.asp', $data);
$arr = split("Set-Cookie:", $html);
$cookie="";
$count=1;
while ($count < count($arr))
{
$cookie.=substr($arr[$count].";", 0, strpos($arr[$count].";",";")+1);
$count++;
}
echo $html."<br><hr><br>";
$html = $this->HTTP_GET('http://www.sefaz.pe.gov.br/sintegra/consulta/exibirResultado.asp', $cookie);
echo $html;
}
任何人都可以幫我嗎?
謝謝。
我無法獲得HTTP 200 OK,我的目標是200,但我只得到302 ...直到如果我在執行GET後 – user3192562
嘗試打開Chrome,按Ctr + Shift + I,然後打開您需要的頁面如果標題是相同的 - 頁面臨時移動從那個地方的兒子。 – RussianVodka