CURL post
<?php /** * Created by PhpStorm. * User: brady * Date: 2017/12/11 * Time: 10:43 */ $ch = curl_init(); $data = array('username'=>'brady','password'=>'2435345'); curl_setopt($ch,CURLOPT_URL,'wang.com/curl/api.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$data); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); $output = curl_exec($ch); //var_dump(curl_error($ch)); curl_close($ch); print_r($output);
接口
<?php /** * Created by PhpStorm. * User: brady * Date: 2017/12/11 * Time: 10:44 */ $data = $_POST; file_put_contents('a.txt',json_encode($data),FILE_APPEND); echo json_encode($data);
调试过程遇到不能解析host,原来要在linux虚拟机也要配置host
vim /etc/hosts
source /etc/hosts