网站建设制作设计营销 大连,广告彩页设计,模板网站外链做不起来,网络服务器无响应改进措施或应对策略类似于dreamhost这类主机服务商#xff0c;是显示fopen 的使用 的。使用php的curl可以实现支持FTP、FTPS、HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE和LDAP。curl 支持SSL证书、HTTP POST、HTTP PUT 、FTP 上传#xff0c;kerberos、基于HTT格式的上传、代理、cookie、用户…类似于dreamhost这类主机服务商是显示fopen 的使用 的。使用php的curl可以实现支持FTP、FTPS、HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE和LDAP。curl 支持SSL证书、HTTP POST、HTTP PUT 、FTP 上传kerberos、基于HTT格式的上传、代理、cookie、用户口令证明、文件传送恢复、http代理通道就最常用的来说是基于http的 get和post方法。 代码实现 1、http的get实现 Php代码 $ch curl_init(http://www.domain.com/api/index.php?test1) ; curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回 curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回 echo $output curl_exec($ch) ; /* 写入文件 */ $fh fopen(out.html, w) ; fwrite($fh, $output) ; fclose($fh) ; 2、http的post实现 Php代码 ?php $url http://www.domain.com/api/ ; $fields array( lnamejustcoding , fnamephplover , titlemyapi, age27 , email1353777303gmail.com , phone1353777303 ); //$post_data implode(,$fields); //open connection $ch curl_init() ; //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL,$url) ; curl_setopt($ch, CURLOPT_POST,count($fields)) ; // 启用时会发送一个常规的POST请求类型为application/x-www-form-urlencoded就像表单提交的一样。 curl_setopt($ch, CURLOPT_POSTFIELDS,$fields); // 在HTTP中的“POST”操作。如果要传送一个文件需要一个开头的文件名 ob_start(); curl_exec($ch); $result ob_get_contents() ; ob_end_clean(); echo $result; //close connection curl_close($ch) ; Php代码 ?php if($_GET[test]) { print_r($_GET); } if($_POST) { print_r($_POST); } 3. php的curl传送cookie 两种方式: 一种是自动: Php代码 curl_setopt($curlHandle, CURLOPT_COOKIEJAR, cookie.txt ); //保存 curl_setopt($curlHandle, CURLOPT_COOKIEFILE, cookie.txt ); //读取 这样COOKIE会自动跟上去. 不过要分两次一是先访问产生cookie接着连结才能用cookie 例子 Php代码 ?php function get_curlcuconent2($filename,$referer) { $cookie_jar tempnam(./tmp,JSESSIONID); $ch curl_init(); curl_setopt($ch, CURLOPT_URL, $filename); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设置文件读取并提交的cookie路径 curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar); $filecontentcurl_exec($ch); curl_close($ch); $ch curl_init(); $hostname www.domain.com; //$refererhttp://www.domain.com/; curl_setopt($ch, CURLOPT_URL, $filename); curl_setopt($ch, CURLOPT_REFERER, $referer); // 看这里你也可以说你从google来 curl_setopt($ch, CURLOPT_USERAGENT, www.domain.com); //$request JSESSIONIDabc6szw15ozvZ_PU9b-8r; //设置POST参数 //curl_setopt($ch, CURLOPT_POSTFIELDS, $request); // 上面这句当然你可以说你是baidu改掉这里的值就ok了可以实现小偷的功能$_SERVER[HTTP_USER_AGENT] //你也可以自己做个 spider 了那么就伪装这里的 CURLOPT_USERAGENT 吧 //如果你要把这个程序放到linux上用php -q执行那也要写出具体的$_SERVER[HTTP_USER_AGENT]伪造的也可以 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar); curl_setopt($ch, CURLOPT_HEADER, false);//设定是否输出页面内容 curl_setopt($ch, CURLOPT_GET, 1); // post,get 过去 $filecontent curl_exec($ch); preg_match_all(/charset(.?)[NULL\\]/is,$filecontent, $charsetarray); if(strtolower($charsetarray[1][0])utf-8) $filecontenticonv( utf-8, gb18030//IGNORE , $filecontent); curl_close($ch); return $filecontent; } ? 一种自定义: Php代码 $header[] Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, text/html, * . /* ; $header[] Accept-Language: zh-cn ; $header[] User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727) ; $header[] Host: .$你的目标HOST; $header[] Connection: Keep-Alive ; $header[] Cookie: .$你的COOKIE串; curl_setopt($curlHandel,CURLOPT_HTTPHEADER,$header); 转载于:https://www.cnblogs.com/Jerry-blog/p/5010158.html