一般json编码格式是{key:value},而表单编码方式则是 key=value&key2=value2。
直接上代码:
代码中这样传传过去 就是FormData方式
$data ="id=230&rid=3533&name=王炎&id_number=35018119800&mobile=1139460"; echo posturl('https://xb.xbUrl',$data); function posturl($url,$data){ $headerArray =array("Content-type:application/x-www-form-urlencoded;charset='utf-8'","Accept:application/x-www-form-urlencoded"); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); echo $output; curl_close($curl); }
原创文章,作者:jamestackk,如若转载,请注明出处:https://blog.ytso.com/273068.html