🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
1. **抓包软件fiddler的用法** [手机抓包设置教程](http://blog.csdn.net/gld824125233/article/details/52588275 ) http://blog.csdn.net/qq_21445563/article/details/51017605 https://www.jianshu.com/p/6c2c8a49945e 2. **利用file_get_contents第三个参数** ``` $postData=array( 'tittle'=>"this is tittle", 'content'=>'this is content', 'publish'=>'this is publish', ); //将数组或者对象解析成 foo=bar&baz=boom&amp这种url格式 // 生成 URL-encode 之后的请求字符串 $postData=http_build_query($postData); $opts = array( 'http'=>array( 'method'=>"POST", 'header'=>"HOST:localhost\r\n". "Content-type:application/x-www-form-urlencoded\r\n" . "content-length:".strlen($postData) . "\r\n", "content"=>$postData, ) ); $context=stream_context_create($opts);//创建资源流上下文 file_get_contents("http://localhost/project/http/test.php",false,$context); fopen也可以: $fp=fopen("http://localhost/project/http/test.php",'r',false,$context); $fclose(); ``` 3. **socket方法** 用到的主要函数:fsockopen ``` $postData=array( 'tittle'=>"this is tittle", 'content'=>'this is content', 'publish'=>'this is publish', ); // 生成 URL-encode 之后的请求字符串 $postData=http_build_query($postData); $fp=fsockopen('localhost',80,$error,$errorStr,5); $request="POST http://localhost/project/http/test.php HTTP/1.1\r\n"; $request.="HOST:localhost\r\n"; $request.="Content-type:application/x-www-form-urlencoded\r\n"; $request.="Content-length:".strlen($postData)."\r\n\r\n"; $request.=$postData; fwrite($fp,$request); while(!feof($fp)){ echo fgets($fp,1024); } fclose($fp); ``` 4. **curl扩展** curl最重要的四个函数: ``` curl_init — 初始化一个cURL会话 curl_multi_setopt — 为 cURL 并行处理设置一个选项 curl_exec — 执行一个cURL会话 curl_close — 关闭一个cURL会话 ``` 例子: ``` $postData=array( 'tittle'=>"this is tittle", 'content'=>'this is content', 'publish'=>'this is publish', ); $ch =curl_init(); //设置提交的url curl_setopt($ch,CURLOPT_URL,$url); //设置数据的提交方式 curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$postData); //提交成功后把数据返回为字符串 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $output=curl_exec($ch); curl_close($ch); echo $output; ```