我遇到問題試圖發送POST請求並得到結果,這裏是我的代碼:發送POST請求的multipart/form-data的
function connect2($hostname,$method,$path,$data,$cookie){
$fp=fsockopen($hostname, 80, $errno, $errstr, 30);
if(!$fp) echo "$errstr($errno)<br>/>\n";
else{
$headers="$method $path HTTP/1.1\r\n";
$headers.= "Host: $hostname\r\n";
if($cookie) $headers.="Cookie: $cookie\r\n";
if($method=="POST") $headers.="Content-length: ".strlen($data)."\r\n";
if($method=="POST") $headers.="Content-Type: multipart/form-data; boundary=---------------------------4358114262792\r\n";
$headers.="Referer: http://ospb.dev.1adw.com/vt/houses/add\r\n";
$headers.="Connection: keep-alive\r\n";
if($method=="POST")$headers.="\r\n\$data\r\n";
$headers.="\r\n";
fwrite($fp, $headers);
$line="";
while(!feof($fp)){
$line.=fgets($fp, 1024);
}
fclose($fp);
}
return $line ;
}
$data="-----------------------------4358114262792\r\n"
."Content-Disposition: form-data; name=\"action\"\r\n\r\n".
"add\r\n".
"-----------------------------4358114262792\r\n".
"Content-Disposition: form-data; name=\"selectedTab\"\r\n\r\n".
"0\r\n".
"-----------------------------4358114262792\r\n".
"Content-Disposition: form-data; name=\"house[officeId]\"\r\n\r\n".
"450\r\n".
"-----------------------------4358114262792\r\n".
"Content-Disposition: form-data; name=\"house[streetId]\"\r\n\r\n".
"968432\r\n".
"-----------------------------4358114262792\r\n".
"Content-Disposition: form-data; name=\"house[number]\"\r\n\r\n".
"20\r\n".
"-----------------------------4358114262792\r\n".
"Content-Disposition: form-data; name=\"house[building]\"\r\n\r\n".
"1\r\n".
"-----------------------------4358114262792\r\n".
"Content-Disposition: form-data; name=\"house[sourceUrl]\"\r\n\r\n".
"http://uk-sozidanie.ru/homes/\r\n".
"-----------------------------4358114262792\r\n".
"Content-Disposition: form-data; name=\"house[statusId]\"\r\n\r\n".
"1\r\n".
"-----------------------------4358114262792\r\n".
"Content-Disposition: form-data; name=\"__token\"\r\n\r\n".
"cfc3901629435\r\n".
"-----------------------------4358114262792--";
...
$b = connect2("ospb.dev.1adw.com", "POST", "/vt/houses/add", $data ,$cookie);
這裏是錯誤:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\cdo\www\add.php on line 46
我只是試圖模擬一個真正的請求,工作正常,並幾乎imidietly返回良好的結果。
加了: 我是否正確計算了我的數據長度?
這個請求不應該持續超過30秒,但我試了120秒,它不返回任何東西。只是沒有迴應:沒有響應頭,沒有任何 – user1956641
然後你需要調試你的請求。 –