解决php curl模拟post请求内容后并下载文件的思路
分类:PHP_Python| 发布:佚名| 查看:341 | 发表时间:2015/12/29
下面代码使用curl模拟post请求链接后直接显示出了文件内容,如何修改成不显示内容而直接下载请求到的.torrent格式文件呢
01 | function curl_post( $header , $data , $url ) |
04 | $res = curl_setopt ( $ch , CURLOPT_URL, $url ); |
05 | curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, FALSE); |
06 | curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, FALSE); |
07 | curl_setopt ( $ch , CURLOPT_HEADER, 0); |
08 | curl_setopt( $ch , CURLOPT_POST, 1); |
09 | curl_setopt( $ch , CURLOPT_POSTFIELDS, $data ); |
10 | curl_setopt ( $ch , CURLOPT_RETURNTRANSFER, 1); |
11 | curl_setopt( $ch ,CURLOPT_HTTPHEADER, $header ); |
12 | $result = curl_exec ( $ch ); |
14 | if ( $result == NULL) { |
20 | $header = array ( "Host:www.bubuol.com" , |
21 | "Content-Type:application/x-www-form-urlencoded" , |
22 | 'User-Agent: Mozilla/4.0 (compatible; MSIE .0; Windows NT 6.1; Trident/4.0; SLCC2;)' ); |
23 | $data = 'action=download&id=26881&uhash=eecf3d3071a7b672c314bc39' ; |
24 | $ret = curl_post( $header , $data , $url ); |
------解决思路----------------------
不要echo $ret;
把$ret写入文件中去。保存起来
------解决思路----------------------
1 | $ret = curl_post( $header , $data , $url ); |
3 | $filename = 'x.torrent' ; |
4 | header( "Content-Type: application/force-download" ); |
5 | header( "Content-Disposition: attachment; filename=$filename" ); |
下载的 x.torrent 用迅雷打开为
