国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 正阳县| 临清市| 惠东县| 开鲁县| 通州区| 澳门| 鞍山市| 株洲县| 安徽省| 奎屯市| 梁河县| 鹤岗市| 泉州市| 腾冲县| 错那县| 甘洛县| 伊金霍洛旗| 佛坪县| 漾濞| 祁连县| 商南县| 平潭县| 高邑县| 阿坝县| 唐山市| 横山县| 吐鲁番市| 五常市| 霍城县| 尉犁县| 桐梓县| 河东区| 昌邑市| 西昌市| 泾川县| 贵州省| 江油市| 景洪市| 昭苏县| 华容县| 武威市|