curl模擬post請求提交

2021-07-26 13:48:35 字數 3021 閱讀 6838

[php]view plain

copy

header(

'content-type:text/html;charset=utf-8'

);  

function

curlpost(

$url

,$data

,$method

)  curl_setopt($ch

, curlopt_returntransfer, true);  

$tmpinfo

= curl_exec(

$ch);

//6.執行

if(curl_errno(

$ch))   

curl_close($ch

);//8.關閉

return

$tmpinfo

;  }  

$data

=array

('name'

=> 

'1234'

);  

$url

="";  $method

="get"

;  $file

=curlpost(

$url

,$data

,$method

);  

$file

=mb_convert_encoding(

$file

,'utf-8'

,'gbk'

);  

echo

$file

;  

當cookie認證登陸的時候

[php]view plain

copy

<?php   

$cookie_file

= tempnam(

'./temp'

,'cookie'

);  

function

weixinpost(

$url

,$data

,$method

,$setcooke

=false,

$cookie_file

=false)  if(

$setcooke

==true)else

curl_setopt($ch

, curlopt_returntransfer, true);  

$tmpinfo

= curl_exec(

$ch);

//6.執行

if(curl_errno(

$ch))   

curl_close($ch

);//8.關閉

return

$tmpinfo

;  }  

$data

=array

('username'

=> 

'***'

,'password'

=>

'***'

);  

$url

="";  $method

="post"

;  $file

=weixinpost(

$url

,$data

,$method

,true,

$cookie_file

);  

echo

$file

;  $url

="";  $method

="get"

;  $file

=weixinpost(

$url

,$data

,$method

,false,

$cookie_file

);  

echo

$file

;  ?>  

如果上述還是無法解決,那麼採用以下方案

[php]view plain

copy

$ch= curl_init();    

$url

= '*******'

;    

$header

= array

(  'cookie:********'

);  

// 新增apikey到header  

// 執行http請求  

curl_setopt($ch

, curlopt_url , 

$url

);   

//如果是https**下面倆行

curl_setopt($ch,curlopt_ssl_verifypeer,false);

curl_setopt($ch,curlopt_ssl_verifyhost,false);  

$res

= curl_exec(

$ch);    

var_dump($res

);    

上面的$header中的陣列中cookie的內容是現在瀏覽器登入,然後開啟控制台,把cookie的資訊貼上進來;如果把cookie貼上進去不行的話試著把cookie中的空格刪除!

curl模擬post請求提交

header content type text html charset utf 8 function curlpost url,data,method curl setopt ch,curlopt returntransfer,true tmpinfo curl exec ch 6.執行 if ...

curl模擬post請求提交

header content type text html charset utf 8 function curlpost url,data,method curl setopt ch,curlopt returntransfer,true tmpinfo curl exec ch 6.執行 if ...

curl模擬post請求提交

header content type text html charset utf 8 function curlpost url,data,method curl setopt ch,curlopt returntransfer,true tmpinfo curl exec ch 6.執行 if ...