解析curl提交GET,POST,Cookie的簡(jiǎn)單方法_PHP教程
推薦:解析PHP中empty is_null和isset的測(cè)試代碼如下: 復(fù)制代碼 代碼如下: ?php $a; $b = false; $c = ''; $d = 0; $e = null; $f = array(); 首先是empty的var_dump輸出: boolean true boolean true boolean true boolean true boolean true boolean true 然后是is_null的輸出: boolean true boolean false bool
本篇文章是對(duì)curl提交GET,POST,Cookie的簡(jiǎn)單方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下 復(fù)制代碼 代碼如下:
<?php
$get_data = array (
"get1"=> "get1",
"get2" => "get2",
"get3" => "get3"
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://test.test.com/test.php?'.http_build_query($get_data));
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11');
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$post_data = array (
"p1" => "test1",
"p2" => "test2",
"p3" => "test3"
);
curl_setopt($curl, CURLOPT_POST, true);
//["CONTENT_TYPE"]=> string(70) "multipart/form-data; boundary=------077a996f5afe"
//要發(fā)送文件,在文件名前面加上@前綴并使用完整路徑。
//使用數(shù)組提供post數(shù)據(jù)時(shí),CURL組件大概是為了兼容@filename這種上傳文件的寫法,默認(rèn)把content_type設(shè)為了multipart/form-data。
//雖然對(duì)于大多數(shù)web服務(wù)器并沒有影響,但是還是有少部分服務(wù)器不兼容。
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
//["CONTENT_TYPE"]=> string(33) "application/x-www-form-urlencoded"
//curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data));
//在沒有需要上傳文件的情況下,盡量對(duì)post提交的數(shù)據(jù)進(jìn)行http_build_query,然后發(fā)送出去,能實(shí)現(xiàn)更好的兼容性,更小的請(qǐng)求數(shù)據(jù)包。
$cookies = array(
'c1'=>'v1',
'c2'=>'v2',
'c3'=>'v3',
);
$cookies_string = '';
foreach($cookies as $name=>$value){
$cookies_string .= $name.'='.$value.';';
}
curl_setopt($curl, CURLOPT_COOKIE, $cookies_string);
$result = curl_exec($curl);
curl_close($curl);
var_dump($result);
exit;
分享:php selectradio和checkbox默認(rèn)選擇的實(shí)現(xiàn)方法詳解本篇文章是對(duì)php selectradio和checkbox默認(rèn)選擇的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下 這是擴(kuò)展yibing的select默認(rèn)選擇的實(shí)現(xiàn)方法 復(fù)制代碼 代碼如下: select name=wuyeleixing size=1 option ?php if($myrow[wuyeleixing]==1) echo(selected);? value=1住
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁(yè)面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語(yǔ)言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國(guó)語(yǔ)言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
PHP教程Rss訂閱編程教程搜索
PHP教程推薦
- 兩種PHP程序?qū)崿F(xiàn)支持頁(yè)面后退的方法
- PHP實(shí)例 PHP實(shí)現(xiàn)定時(shí)生成HTML網(wǎng)站首頁(yè)
- 淺談PHP數(shù)組讀取的循環(huán)操作
- 淺談微軟對(duì)PHP支持的改進(jìn) 及其它一些胡言亂語(yǔ)
- PHP程序字符串處理函數(shù)
- 用PHPINFO來(lái)實(shí)現(xiàn)PHP的配置統(tǒng)計(jì)過程
- vim下高亮顯示php代碼
- 解析link_mysql的php版
- 基于Zend的Captcha機(jī)制的應(yīng)用
- PHP實(shí)現(xiàn)首頁(yè)自動(dòng)選擇語(yǔ)言轉(zhuǎn)跳
- 相關(guān)鏈接:
- 教程說明:
PHP教程-解析curl提交GET,POST,Cookie的簡(jiǎn)單方法
。