日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

php curl中x-www-form-urlencoded与multipart/form-data 方式 Post 提交数据详解

發(fā)布時(shí)間:2023/12/19 综合教程 35 生活家
生活随笔 收集整理的這篇文章主要介紹了 php curl中x-www-form-urlencoded与multipart/form-data 方式 Post 提交数据详解 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

multipart/form-data 方式

post的curl庫,模擬post提交的時(shí)候,默認(rèn)的方式 multipart/form-data ,這個算是post提交的幾個基礎(chǔ)的實(shí)現(xiàn)方式。

$postUrl = '';
$postData = array(
'user_name'=>$userName,
'identity_no'=>$idCardNo
);

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $postUrl);
curl_setopt($curl, CURLOPT_USERAGENT,'Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop verifying certificate
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$r = curl_exec($curl);
curl_close($curl);

print_r($r);

想用的可以直接拿去試試

x-www-form-urlencoded方式

php的curl庫進(jìn)行post提交還是蠻方便的。但是提交方式不同,contentType 不同導(dǎo)致你的api是否能接收到數(shù)據(jù)也是個變數(shù),這里來個簡單的實(shí)例。

$postUrl = '';
$postData = array(
'user_name'=>$userName,
'identity_no'=>$idCardNo
);
$postData = http_build_query($postData);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $postUrl);
curl_setopt($curl, CURLOPT_USERAGENT,'Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop verifying certificate
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$r = curl_exec($curl);
curl_close($curl);

print_r($r);

關(guān)鍵一段代碼是

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));

以上是云棲社區(qū)小編為您精心準(zhǔn)備的的內(nèi)容,在云棲社區(qū)的博客、問答、公眾號、人物、課程等欄目也有的相關(guān)內(nèi)容,歡迎繼續(xù)使用右上角搜索按鈕進(jìn)行搜索windows , 數(shù)據(jù) , array opera curlformadd 參數(shù)詳解、urlencodedformentity、xwwwform urlencoded、formurlencoded、wwwform urlencoded,以便于您獲取更多的相關(guān)知識。

總結(jié)

以上是生活随笔為你收集整理的php curl中x-www-form-urlencoded与multipart/form-data 方式 Post 提交数据详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。