php的fsockopen post表单

WBOY
Freigeben: 2016-06-23 14:32:18
Original
896 Leute haben es durchsucht

好久没用fsockopen,居然忘记了post的格式。 fsockopen post表单 2006-04-27 14:42:05 bailing

需要注意: 1.form的数据必须用rawurlencode编码联起来。 2.必须提交content-length长度 3.post表单的数据必须跟在\r\n\r\n后面。$data["channel"]=$moRow['serviceCode'];$data["mobile"]=$moRow['mobile'];$data["gateway"]=$moRow['gateway'];$data["isp"]=$moRow['isp'];$data["linkid"]=$moRow['linkid'];$data["msg"]=$content;while (list($k,$v) = each($data)) {$post .= rawurlencode($k)."=".rawurlencode($v)."&";}$post = substr( $post , 0 , -1 );$len = strlen($post);//发送$host = "localhost";$file = "/mtApp/send.php";$fp = @fsockopen( $host , 80, $errno, $errstr, 30);if (!$fp) {    echo "$errstr ($errno)\n";} else {	$receive = '';    $out = "POST $file HTTP/1.1\r\n";    $out .= "Host: $host\r\n";	$out .= "Content-type: application/x-www-form-urlencoded\r\n";    $out .= "Connection: Close\r\n";	$out .= "Content-Length: $len\r\n";	$out .="\r\n";	$out .= $post."\r\n";	echot($out);    fwrite($fp, $out);    while (!feof($fp)) {        $receive .= fgets($fp, 128);    }    fclose($fp);}echo $receive;	一个普通的post头POST /cgi-bin/tech/method.cgi HTTP/1.1Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*Referer: http://localhost//other.htmlAccept-Language: zh-cnContent-Type: application/x-www-form-urlencodedAccept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)Host: localhost:8080Content-Length: 9Connection: Keep-Alive
Nach dem Login kopieren

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!