php模拟post的方法
php主动post数据到jsp
采用哪种方式好?
最好有例子,谢谢
------解决方案--------------------
后台模拟 哪种都差不多 最常用的curl模块
------解决方案--------------------
php codefunction post_url($url, $post = , $host = www.ydtuiguang.com, $referrer = 'http://www.ydtuiguang.com/', $proxy = -1){ if(function_exists(curl_init)){ $ch = @curl_init(); @curl_setopt($ch, curlopt_url, $url); if(!empty($proxy[address])) @curl_setopt($ch, curlopt_proxy, strpos($proxy[address], http) === 0 ? $proxy[address] : http://.$proxy[address]); if(!empty($proxy[account]) && !empty($proxy[password])) @curl_setopt($ch, curlopt_proxyuserpwd, $proxy[account].:.$proxy[password]); @curl_setopt($ch, curlopt_referer, $referrer); @curl_setopt($ch, curlopt_useragent, mozilla/4.0 (compatible; msie 7.0; windows nt 5.0)); @curl_setopt($ch, curlopt_cookiejar, cookie_file_path); @curl_setopt($ch, curlopt_cookiefile, cookie_file_path); @curl_setopt($ch, curlopt_header, 0); @curl_setopt($ch, curlopt_returntransfer, 1); @curl_setopt($ch, curlopt_followlocation, 1); @curl_setopt($ch, curlopt_timeout, 1000); if (!empty($post)) { @curl_setopt($ch, curlopt_post, 1); @curl_setopt($ch, curlopt_postfields, $post); } $result = @curl_exec($ch); @curl_close($ch); }elseif(function_exists(fsockopen)){ $httpheader = post .$url. http/1.1\r\n; $httpheader .= accept: */*\r\n; $httpheader .= accept-language: zh-cn\r\n; $httpheader .= referer: .$referrer.\r\n; $httpheader .= content-type: application/x-www-form-urlencoded\r\n; $httpheader .= user-agent: mozilla/4.0 (compatible; msie 7.0; windows nt 5.1)\r\n; $httpheader .= host: .$host.\r\n; $httpheader .= content-length: .strlen($post).\r\n; $httpheader .= connection: keep-alive\r\n; $httpheader .= \r\n; $httpheader .= $post; $fd = fsockopen($host, 80); fwrite($fd, $httpheader); $result = ; while(!feof($fd)){ $result .= fread($fd, 8192); } fclose($fd); }elseif(function_existes('file_get_contents')){ $httpheader = post .$url. http/1.1\r\n; $httpheader .= accept: */*\r\n; $httpheader .= accept-language: zh-cn\r\n; $httpheader .= referer: .$referrer.\r\n; $httpheader .= content-type: application/x-www-form-urlencoded\r\n; $httpheader .= user-agent: mozilla/4.0 (compatible; msie 7.0; windows nt 5.1)\r\n; $httpheader .= host: .$host.\r\n; $httpheader .= content-length: .strlen($post).\r\n; $httpheader .= connection: keep-alive\r\n; $opts = array( 'http'=>array( 'method'=>post, 'header'=>$httpheader, 'content'=>$post ) ); $context = stream_context_create($opts); $result = file_get_contents($url, 'r', $context); } return $result;}
------解决方案--------------------
探讨
后台模拟 哪种都差不多 最常用的curl模块