国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

PHP 5.6 的Curl POST

2019-11-06 06:05:36
字體:
供稿:網(wǎng)友

1、一般的http post 支持提交鍵值對和二進(jìn)制數(shù)據(jù),win 下使用php 5.6的curl可以這樣模擬

如下代碼:

        $ch = curl_init();                //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);	//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);                curl_setopt($ch, CURLOPT_URL,$url);        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        curl_setopt($ch, CURLOPT_TIMEOUT, 30);        curl_setopt($ch, CURLOPT_POST, true);                //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));        //curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-type:application/x-www-form-urlencode"));        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);如果data是一個(gè)鍵值對的數(shù)組,那么抓包的結(jié)果都是:

POST /IG_ePolicy/EncryptPassWord HTTP/1.1Host: Accept: */*Content-Length: 151Expect: 100-continueContent-Type: application/x-www-form-urlencoded; boundary=------------------------d30a0827949e2a44--------------------------d30a0827949e2a44Content-Disposition: form-data; name="Password"password--------------------------d30a0827949e2a44--

就算是設(shè)置了Content-Type 也是同樣的結(jié)果,就是curl默認(rèn)是以二進(jìn)制數(shù)據(jù)的方式提交給服務(wù)器的和我們平常的表單提交并不一致服務(wù)端如果使用鍵值對的方式獲取就有可能取不到不,所以這里$data 應(yīng)該使用http_build_query($data) 編碼一次。

2、表單正確的提交方式醫(yī)改如下代碼:

        $data = array("Password"=>"password");                $ch = curl_init();                //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);	    //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);                curl_setopt($ch, CURLOPT_URL,$url);        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        curl_setopt($ch, CURLOPT_TIMEOUT, 30);        curl_setopt($ch, CURLOPT_POST, true);                 // curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));        //curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-type:application/x-www-form-urlencode"));        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));post到服務(wù)器端的數(shù)據(jù)就是:
POST /IG_ePolicy/EncryptPassword HTTP/1.1Host: Accept: */*Content-Length: 17Content-Type: application/x-www-form-urlencodedPassword=password


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 广昌县| 察隅县| 鲁山县| 青岛市| 多伦县| 黎川县| 焉耆| 韶关市| 辽宁省| 随州市| 德化县| 河南省| 张家港市| 黄梅县| 天长市| 法库县| 垫江县| 汝城县| 郎溪县| 从化市| 达孜县| 井研县| 怀远县| 久治县| 繁昌县| 清流县| 安阳市| 南岸区| 汉中市| 天气| 邳州市| 长岛县| 建始县| 台前县| 成武县| 乾安县| 聂拉木县| 青冈县| 玉屏| 伊春市| 揭西县|