導航:首頁 > 編程語言 > phpcurlsetoptget

phpcurlsetoptget

發布時間:2022-03-07 17:21:34

『壹』 php curl get 參數

$cu = curl_init();
curl_setopt($cu, CURLOPT_URL, $url);
curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($cu);
curl_close($cu);
其中$url變數可以是完整的URL+參數

『貳』 php curl 無法將url中的內容獲取到變數之中

functioncurl_get_contents($url){
$curl=curl_init();
//設置你需要抓取的URL
curl_setopt($curl,CURLOPT_URL,$url);
//設置header
curl_setopt($curl,CURLOPT_HEADER,1);
//設置cURL參數,要求結果保存到字元串中還是輸出到屏幕上。
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
//運行cURL,請求網頁
$data=curl_exec($curl);
//關閉URL請求
curl_close($curl);
return$data
}

『叄』 php使用curl抓取一個網站的內容被拒絕

剛寫的。希望有用

<?php
$binfo=array('Mozilla/4.0(compatible;MSIE8.0;WindowsNT5.1;Trident/4.0;.NETCLR2.0.50727;InfoPath.2;AskTbPTV/5.17.0.25589;AlexaToolbar)','Mozilla/5.0(WindowsNT5.1;rv:22.0)Gecko/20100101Firefox/22.0','Mozilla/4.0(compatible;MSIE8.0;WindowsNT5.1;Trident/4.0;.NET4.0C;AlexaToolbar)','Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1;SV1)',$_SERVER['HTTP_USER_AGENT']);
//218.242.124.16*
//125.90.88.*
$cip='218.242.124.'.mt_rand(0,254);
$xip='218.242.124.'.mt_rand(0,254);
$header=array(
'CLIENT-IP:'.$cip,
'X-FORWARDED-FOR:'.$xip,
);
functiongetimgs($url,$data,$userinfo,$header)
{
$ch=curl_init();
$timeout=5;
curl_setopt($ch,CURLOPT_URL,"$url");
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch,CURLOPT_REFERER,"http://www.sgs.gov.cn/lz/etpsInfo.do?method=index");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_USERAGENT,"$userinfo");
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$contents=curl_exec($ch);
curl_close($ch);
return$contents;
}

$url='http://www.sgs.gov.cn/lz/etpsInfo.do?method=doSearch';
$u=$binfo[mt_rand(0,3)];
$data=array(
'keyWords'=>'上海科波',
'searchType'=>'1'
);

$html=(getimgs($url,$data,$u,$header));
//替換鏈接地址
$html=str_replace('href="#"','href="http://www.sgs.gov.cn/lz/etpsInfo.do?method=doSearch#"',$html);

echo$html;


?>

『肆』 php curl 如何接收

<?php
/*這是個curlget方法實例,$url是需要獲取的地址*/
$url="http://www.hao123.com/";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$data=curl_exec($ch);//講上面url頁面的源代碼獲取並保存到$data這個變數中
curl_close($ch);
echo$data;
?>

『伍』 如何在php中獲取curl請求的請求頭信息及相應頭信息

<?php
$url='http://demo.zjmainstay.cn';
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_HEADER,true);//返回頭信息
curl_setopt($ch,CURLOPT_NOBODY,true);//不返回內容
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//返回數據不直接輸出
$content=curl_exec($ch);//執行並存儲結果
curl_close($ch);
echo$content;

更多關於phpcURL的內容,請參考我的博客《PHPcURL應用》
http://www.zjmainstay.cn/php-curl

『陸』 php curl如何直接轉發當前php接收的headersget請求如何直接轉發get參數post請求如何直接轉發post參數

本文實例講述了php使用CURL模擬GET與POST向微信介面提交及獲取數據的方法。分享給大家供大家參考,具體如下:
php CURL函數可以模仿用戶進行一些操作,如我們可以模仿用戶提交數據也可以模仿用戶進行網站訪問了,下面我們來介紹利用CURL模擬進行微信介面的GET與POST例子,例子非常的簡單就兩個:
Get提交獲取數據
/**
* @desc 獲取access_token
* @return String access_token
*/
function getAccessToken(){
$AppId = '1232assad13213123';
$AppSecret = '2312312321adss3123213';
$getUrl = 'htq.com/cgi-bin/token?grant_type=client_credential&appid='.$AppId.'&secret='.$AppSecret;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $getUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURL_SSLVERSION_SSL, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($ch);
$response = json_decode($data);
return $response->access_token;
}

post提交獲取數據
/**
* @desc 實現天氣內容回復
*/
public function testWeixin(){
$access_token = $this->getAccessToken();
$customMessageSendUrl = 'ht.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
$description = '今天天氣的詳細信息(從第三方獲取)。';
$url = ttpr.com/';
$picurl = 'her.com/';
$postDataArr = array(
'touser'=>'OPENID',
'msgtype'=>'news',
'news'=>array(
'articles'=>array(
'title'=>'當天天氣',
'description'=>$description,
'url'=>$url,
'picurl'=>$picurl,
),
),
);
$postJosnData = json_encode($postDataArr);
$ch = curl_init($customMessageSendUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postJosnData);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($ch);
var_mp($data);
}

例子相對來說比較簡單也沒有什麼好詳細分析的了,大家照抄就可以實現我們想要的功能了.

『柒』 PHP curl get cookies

跟GET/POST沒啥關系,直接用
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
存儲提交後得到的cookie數據即可

更多PHPcURL的內容,請參考我的博客《PHPcURL實現模擬登錄與採集使用方法詳解教程》

『捌』 能不能把PHP CURL提交的GET或POST請求完整的列印

表單提交中 Get 和 Post 方式的區別:
1、get 是從伺服器上獲取數據,post 是向伺服器傳送數據。
2、get 是把參數數據隊列加到提交表單的 ACTION 屬性所指的 URL 中,值和表單內各個欄位 一一對應,在 URL 中可以看到。post 是通過 HTTPpost 機制,將表單內各個欄位與其內容放 置在 HTML HEADER 內一起傳送到 ACTION 屬性所指的 URL 地址。
3、對於 get 方式,伺服器端用 Request.QueryString 獲取變數的值,對於 post 方式,服務 器端用 Request.Form 獲取提交的數據。
4、get 傳送的數據量較小,不能大於 2KB。post 傳送的數據量較大,一般被默認為不受限 制。但理論上,IIS4 中最大量為 80KB,IIS5 中為 100KB。
5、get 安全性非常低,post 安全性較高。

『玖』 php curl怎麼以get方式提交

//初始化
$ch = curl_init();
//設置選項,包括URL
curl_setopt($ch, CURLOPT_URL, "您要提交的網址");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
//執行並獲取HTML文檔內容
$output = curl_exec($ch);
//釋放curl句柄
curl_close($ch);
//列印獲得的數據
print_r($output);

『拾』 php curl get 下載遠程zip文件保存在本地例子

<?php

if($_POST['submit']){
$url=$_POST['url']; //取得提交過來的地址http://hu60.cn/wap/0wap/addown.php/fetion_sms.zip
$url=urldecode($url);
$fname=basename("$url"); //返迴路徑中的文件名部分 fetion_sms.zip
$str_name=pathinfo($fname); //以數組的形式返迴文件路徑的信息
$extname=strtolower($str_name['extension']); //把擴展名轉換成小寫
//$uptypes=explode(",",$forum_upload); //取得可以上傳的文件格式
//$size=getFileSize($url);

$time=date("Ymd",time());

$upload_dir="./upload/";//上傳的路徑
$file_name=$time.rand(1000,9999).'.'.$fname;
$dir=$upload_dir.$file_name;//創建上傳目錄

//判斷目錄是否存在 不存在則創建
if(!file_exists($upload_dir)){
mkdir($upload_dir,0777,true);
}

$contents=curl_download($url,$dir);

if($contents){
echo "下載成功";
}else{
echo "下載失敗";
}

}

function curl_download($url, $dir) {
$ch = curl_init($url);
$fp = fopen($dir, "wb");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
$res=curl_exec($ch);
curl_close($ch);
fclose($fp);
return $res;
}

?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>遠程下載文件</title>
<form name="upform" method="post" action="" enctype='multipart/form-data'>
<input name='url' type='text' size='20'/>
<input type='submit' name='submit' value='遠程下載'/>
</form>
</body>
</html>

閱讀全文

與phpcurlsetoptget相關的資料

熱點內容
優信二手車解壓後過戶 瀏覽:62
Windows常用c編譯器 瀏覽:778
關於改善國家網路安全的行政命令 瀏覽:833
安卓如何下載網易荒野pc服 瀏覽:654
javainetaddress 瀏覽:104
蘋果4s固件下載完了怎麼解壓 瀏覽:1003
命令zpa 瀏覽:286
python編譯器小程序 瀏覽:945
在app上看視頻怎麼光線調暗 瀏覽:540
可以中文解壓的解壓軟體 瀏覽:593
安卓卸載組件應用怎麼安裝 瀏覽:913
使用面向對象編程的方式 瀏覽:340
程序員項目經理的年終總結範文 瀏覽:930
內衣的加密設計用來幹嘛的 瀏覽:433
淮安數據加密 瀏覽:292
魔高一丈指標源碼 瀏覽:982
松下php研究所 瀏覽:168
c回調java 瀏覽:401
夢幻端游長安地圖互通源碼 瀏覽:746
電腦本地文件如何上傳伺服器 瀏覽:314