使用php模拟post提交数据

使用php模拟post提交数据

PHP代码
  1. <?php   
  2. $target = "http://www.xxxx.com/xxxx.php";   
  3. $host = "www.xxxx.com";   
  4. $msg = "id=1&pw=1";   
  5. $httpheader = "POST ".$target." HTTP/1.1\r\n";   
  6. $httpheader .= "Accept:*/*\r\n";   
  7. $httpheader .= "Accept-Language:zh-cn\r\n";   
  8. $httpheader .= "Referer:".$target."\r\n";   
  9. $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";   
  10. $httpheader .= "User-Agent:Mozilla/4.0(compatible;MSIE 7.0;Windows NT 5.1)\r\n";   
  11. $httpheader .= "Host:".$host."\r\n";   
  12. $httpheader .= "Content-Length:".strlen($msg)."\r\n";   
  13. $httpheader .= "Connection:Keep-Alive\r\n";   
  14. $httpheader .= "\r\n";   
  15. $httpheader .= $msg;   
  16. $fd = fsockopen($host,80);   
  17. fwrite($fd,$httpheader);   
  18. $gets = "";   
  19. while(!feof($fd)){   
  20. $gets .= fread($fd,8192);   
  21. }   
  22. fclose($fd);   
  23. echo "ok";   
  24. echo $gets;   
  25. ?>  
原文地址:https://www.cnblogs.com/rooney/p/1407331.html