熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> PHP編程 >> 正文

解析curl提交GET,POST,Cookie的簡單方法

2022-06-13   來源: PHP編程 
本篇文章是對curl提交GETPOSTCookie的簡單方法進行了詳細的分析介紹需要的朋友參考下   復制代碼 代碼如下:

  
<?php
$get_data = array (
"get"=> "get"
"get" => "get"
"get" => "get"
);
$curl = curl_init();
curl_setopt($curl CURLOPT_URL http_build_query($get_data));
curl_setopt($curl CURLOPT_USERAGENT Mozilla/ (Windows NT ; WOW) AppleWebKit/ (KHTML like Gecko) Chrome/ Safari/);
curl_setopt($curl CURLOPT_HEADER false);
curl_setopt($curl CURLOPT_RETURNTRANSFER true);
curl_setopt($curl CURLOPT_FOLLOWLOCATION true);
$post_data = array (
"p" => "test"
"p" => "test"
"p" => "test"
);
curl_setopt($curl CURLOPT_POST true);
//["CONTENT_TYPE"]=> string() "multipart/formdata; boundary=afafe"
//要發送文件在文件名前面加上@前綴並使用完整路徑
//使用數組提供post數據時CURL組件大概是為了兼容@filename這種上傳文件的寫法默認把content_type設為了multipart/formdata
//雖然對於大多數web服務器並沒有影響但是還是有少部分服務器不兼容
curl_setopt($curl CURLOPT_POSTFIELDS $post_data);
//["CONTENT_TYPE"]=> string() "application/xwwwformurlencoded"
//curl_setopt($curl CURLOPT_POSTFIELDS http_build_query($post_data));
//在沒有需要上傳文件的情況下盡量對post提交的數據進行http_build_query然後發送出去能實現更好的兼容性更小的請求數據包
$cookies = array(
c=>v
c=>v
c=>v
);
$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;


From:http://tw.wingwit.com/Article/program/PHP/201311/21207.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.