首页 > 代码库 > php仿照html post 请求

php仿照html post 请求

// $api 请求的地址
$api="http://42.121.116.250/index.php?m=yp&c=Ipadpra_two&a=login";

// $params 请求的参数 array
$params=array(‘userid‘=>39,‘user_name‘=>‘18790527249‘,‘password‘=>‘654321‘);

//创建一个资源
$ch = curl_init();

//把路径放进去
curl_setopt( $ch, CURLOPT_URL, $api );

// 以返回的形式接收信息
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );

// 设置为POST方式
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params ) );


// 不验证https证书


curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );

curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/x-www-form-urlencoded;charset=UTF-8‘,
‘Accept: application/json‘,));

//发送数据
$response = curl_exec( $ch );
//查看结果
echo $response;

php仿照html post 请求