?戒護浣跨??url: ? curl?-s?http://10.10.69.61/threads/foo/bar/page/1/m/n?-d?content=body?-X?PUT?
curl???浣跨??RL璇?娉???浼?????浠跺伐?鳳?????FTP??FTPS??HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE??LDAP??curl?????SSL璇?涔???HTTP POST??HTTP PUT ??FTP 涓?浼?锛?kerberos???轟?HTT?煎???涓?浼???浠g????cookie???ㄦ?鳳??d護璇???????浠朵????㈠???http浠g????????澶ч???朵????ㄧ????宸с??璇??????????
????hp榛?璁ゅ苟涓?杩?琛?姝ら」???界???╁?锛?浣?杩???????锛?????娌℃??璁╁??????缃??????寮?PHP瀹?瑁???褰?锛???绱?互涓?涓?涓???浠?ssleay32.dll??libeay32.dll?? php_curl.dll锛?涓?涓??瘋??扮郴缁???褰?涓???system32??浠跺す涓?锛?淇???hp.ini??浠訛??懼??extension= php_curl.dll琛?锛??繪?????㈢??;?鳳?淇?瀛?锛????????″?ㄣ???ㄧ???圭??褰?涓?寤虹??涓?涓?PHP??浠訛???瀹瑰?涓?
$ch = curl_init(??http://www.php.net??);
curl_exec($ch);
curl_close($ch);
棰?瑙?濡????芥??寮?http://www.php.net??璇?璇存??灏卞??瑁?????浜???
?充?linux??unix??瀹?瑁???浠ヨ?楹葷???浜?锛?寰?浠?http://curl.haxx.se/???朵?缃?绔?涓?涓?杞?url搴?
____________________________________________________________
浠ヤ??充?姝ゅ?芥?闆??椤逛嬌?ㄥ????
bool curl_setopt (int ch, string option, mixed value)
curl_setopt()?芥?闆?涓轟?涓?CURL浼?璇?璁劇疆??椤廣??option???版??浣??寵???璁劇疆锛?value??杩?涓???椤圭?瀹????箋??
涓?????椤圭???煎?琚?浣?涓洪?挎?村艦浣跨????ption???頒腑??瀹?)锛?
??
* CURLOPT_INFILESIZE: 褰?浣?涓?浼?涓?涓???浠跺?拌?绋?绔??癸?杩?涓???椤瑰??璇?PHP浣?涓?浼???浠剁??澶у???
* CURLOPT_VERBOSE: 濡???浣???URL?ュ??姣?涓?浠舵??澶???浜???锛?璁劇疆杩?涓???椤逛負涓?涓????跺?箋??
* CURLOPT_HEADER: 濡???浣??蟲??涓?涓?澶村?????ㄨ??轟腑锛?璁劇疆杩?涓???椤逛負涓?涓????跺?箋??
* CURLOPT_NOPROGRESS: 濡???浣?涓?浼?PHP涓?URL浼?杈??劇ず涓?涓?杩?绋??★?璁劇疆杩?涓???椤逛負涓?涓????跺?箋??娉ㄦ??锛?PHP???ㄨ?劇疆杩?涓???椤逛負???跺?鹼?浣?搴?璇ヤ?浠?涓轟?璋?璇????????ユ?瑰??杩?涓???椤廣??
* CURLOPT_NOBODY: 濡???浣?涓??沖?ㄨ??轟腑????body?ㄥ??锛?璁劇疆杩?涓???椤逛負涓?涓????跺?箋??
* CURLOPT_FAILONERROR: 濡???浣??寵??HP?ㄥ??????璇?(HTTP浠g??杩???澶т?绛?浜?300)?訛?涓??劇ず锛?璁劇疆杩?涓???椤逛負涓?浜洪???跺?箋??榛?璁よ?涓烘??杩???涓?涓?姝e父椤碉?蹇界?ヤ唬????
* CURLOPT_UPLOAD: 濡???浣??寵??HP涓轟?浼?????澶?锛?璁劇疆杩?涓???椤逛負涓?涓????跺?箋??
* CURLOPT_POST: 濡???浣???HP?誨??涓?涓?姝h???HTTP POST锛?璁劇疆杩?涓???椤逛負涓?涓????跺?箋??杩?涓?POST???????? application/x-www-from-urlencoded 绫誨??锛?澶??拌?HTML琛ㄥ??浣跨?ㄣ??
* CURLOPT_FTPLISTONLY: 璁劇疆杩?涓???椤逛負???跺?鹼?PHP灏?????TP????褰?????琛ㄣ??
* CURLOPT_FTPAPPEND: 璁劇疆杩?涓???椤逛負涓?涓????跺?鹼?PHP灏?搴??ㄨ?绋???浠朵唬?胯???瀹???
* CURLOPT_NETRC: 璁劇疆杩?涓???椤逛負涓?涓????跺?鹼?PHP灏??ㄤ??? ~./netrc ??浠朵腑?ユ?句?瑕?寤虹??杩??ョ??杩?绋?绔??圭???ㄦ?峰????瀵?????
* CURLOPT_FOLLOWLOCATION: 璁劇疆杩?涓???椤逛負涓?涓????跺??璞???Location: ??)??澶達????″?ㄤ???瀹?褰???HTTP澶寸??涓??ㄥ??????(娉ㄦ??杩?????褰???锛?PHP灏?????褰㈠? ??Location: ????澶???
* CURLOPT_PUT: 璁劇疆杩?涓???椤逛負涓?涓????跺?煎?葷??TTP涓?浼?涓?涓???浠躲??瑕?涓?浼?杩?涓???浠跺?椤昏?劇疆CURLOPT_INFILE??CURLOPT_INFILESIZE??椤?
* CURLOPT_MUTE: 璁劇疆杩?涓???椤逛負涓?涓????跺?鹼?PHP瀵逛?CURL?芥?闆?瀹??ㄦ?榛???
* CURLOPT_TIMEOUT: 璁劇疆涓?涓??挎?村艦?幫?浣?涓烘??澶у歡缁?澶?灏?绉???
* CURLOPT_LOW_SPEED_LIMIT: 璁劇疆涓?涓??挎?村艦?幫??у?朵???澶?灏?瀛?????
* CURLOPT_LOW_SPEED_TIME: 璁劇疆涓?涓??挎?村艦?幫??у?跺?灏?绉?浼???CURLOPT_LOW_SPEED_LIMIT瑙?瀹???瀛????般??
* CURLOPT_RESUME_FROM: 浼???涓?涓?????瀛?????绉誨?闆?????挎?村艦???幫?(浣??寵漿绉誨?扮??寮?濮?琛ㄥ??)??
* CURLOPT_SSLVERSION: 浼???涓?涓?????SSL???????垮???般??榛?璁?HP灏?琚?瀹???宸卞??????纭?瀹?锛??ㄦ?村???瀹??ㄤ腑浣?蹇?椤繪??宸ヨ?劇疆??
* CURLOPT_TIMECONDITION: 浼???涓?涓??垮???幫???瀹???涔?澶???CURLOPT_TIMEVALUE???般??浣???浠ヨ?劇疆杩?涓????頒負TIMECOND_IFMODSINCE ?? TIMECOND_ISUNMODSINCE??杩?浠??ㄤ?HTTP??
* CURLOPT_TIMEVALUE: 浼???涓?涓?浠?1970-1-1寮?濮??扮?闆?ㄧ??绉??般??杩?涓??堕?村?琚?CURLOPT_TIMEVALUE??椤逛?涓烘??瀹??間嬌?????琚?榛?璁?IMECOND_IFMODSINCE浣跨?ㄣ??
涓?????椤圭???煎?琚?浣?涓哄??绗?覆锛?
??
* CURLOPT_URL: 杩???浣??崇??HP??????URL?闆????浣?涔???浠ュ?ㄧ??url_init()?芥?闆??濮????惰?劇疆杩?涓???椤廣??
* CURLOPT_USERPWD: 浼???涓?涓?褰㈠?[username]:[password]椋??肩??瀛?绗?覆,浣???HP?昏??ャ??
* CURLOPT_PROXYUSERPWD: 浼???涓?涓?褰㈠?[username]:[password] ?煎???瀛?绗?覆?昏???TTP浠g????
* CURLOPT_RANGE: 浼???涓?涓?浣??蟲??瀹??????淬??瀹?搴?璇ユ????X-Y???煎?锛?X??Y??琚??ゅ?????HTTP浼??????鋒??????涓??撮??锛??ㄩ???ユ?ュ????(X-Y,N-M)??
* CURLOPT_POSTFIELDS: 浼???涓?涓?浣?涓?TTP ??POST????浣????????版????瀛?绗?覆??
* CURLOPT_REFERER: ??TTP璇鋒?涓?????涓?涓???referer??澶寸??瀛?绗?覆??
* CURLOPT_USERAGENT: ??TTP璇鋒?涓?????涓?涓???user-agent??澶寸??瀛?绗?覆??
* CURLOPT_FTPPORT: 浼???涓?涓?????琚?ftp ??POST????浠や嬌?ㄧ??IP?闆????杩?涓?POST??浠ゅ??璇?杩?绋????″?ㄥ?昏??ユ??浠???瀹???IP?闆????杩?涓?瀛?绗?覆??浠ユ??涓?涓?IP?闆??锛?涓?涓?涓繪?哄??锛?涓?涓?缃?缁????㈠??(??NIX涓?)锛???????-??(浣跨?ㄧ郴缁?榛?璁?P?闆??)??
* CURLOPT_COOKIE: 浼???涓?涓?????HTTP cookie??澶磋??ャ??
* CURLOPT_SSLCERT: 浼???涓?涓?????PEM?煎?璇?涔???瀛?绗?覆??
* CURLOPT_SSLCERTPASSWD: 浼???涓?涓?????浣跨??URLOPT_SSLCERT璇?涔??????瀵?????
* CURLOPT_COOKIEFILE: 浼???涓?涓?????cookie?版??????浠剁????瀛???瀛?绗?覆??杩?涓?cookie??浠跺??浠ユ??Netscape?煎?锛???????瀛??ㄦ??浠朵腑??HTTP椋??肩??澶淬??
* CURLOPT_CUSTOMREQUEST: 褰?杩?琛?HTTP璇鋒??訛?浼???涓?涓?瀛?绗??GET??HEAD浣跨?ㄣ??涓鴻?琛?DELETE???跺????浣?????????锛???ass a string to be used instead of GET or HEAD when doing an HTTP request. This is useful for doing or another, more obscure, HTTP request. 娉ㄦ??: ?ㄧ‘璁や??????″?ㄦ?????戒護??涓?瑕??昏??峰????涓???????椤矽?姹?涓?涓???浠舵??杩???杩?浣跨??open()?芥?拌?峰?)锛???
* CURLOPT_FILE: 杩?涓???浠跺???浣??劇疆浼?????杈??烘??浠訛?榛?璁ゆ??STDOUT.
* CURLOPT_INFILE: 杩?涓???浠舵??浣?浼???杩??ョ??杈??ユ??浠躲??
* CURLOPT_WRITEHEADER: 杩?涓???浠跺????浣?杈??虹??澶撮?ㄥ????
* CURLOPT_STDERR: 杩?涓???浠跺??????璇???涓???stderr???ㄦ?ヨ?峰????瑕??誨???椤甸?㈢??渚?瀛?,褰?????娉???姣?娆℃??璁擱?界?誨?涓?娆?????瑕???浜哄?????矽?浜?.
????涓?浠?????缃?绔??h??ョ??渚?瀛?:
渚?涓?锛?
$cookie_jar = tempnam(??./tmp??,'cookie??);
$ch = curl_init(); curl_setopt($ch,CURLOPT_URL, ??http://******??);
curl_setopt($ch, CURLOPT_POST, 1);
$request = ??email_address=&password=&action=??;
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);?
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);?//??杩????ョ??cookie淇℃??淇?瀛???cookie_jar??浠朵腑
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);?//璁懼??杩??????版?????????ㄦ?劇ず
curl_setopt($ch, CURLOPT_HEADER, false);?//璁懼???????劇ず澶翠俊??
curl_setopt($ch, CURLOPT_NOBODY, false);//璁懼????????洪〉?㈠??瀹? curl_exec($ch);
curl_close($ch); //get data after login
渚?浜?锛?
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, ??http://*****??);
curl_setopt($ch2, CURLOPT_HEADER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);
$orders = curl_exec($ch2);
echo ??;
echo strip_tags($orders);
echo ??;
curl_close($ch2); 瀹?璺佃????寰?绋沖??:)
渚?涓?锛?
set_time_limit(0);
function _rand() {
$length=26;
$chars = ??0123456789abcdefghijklmnopqrstuvwxyz??;
$max = strlen($chars) ?? 1;
mt_srand((double)microtime() * 1000000);
$string = ??;
for($i = 0; $i < $length; $i++) {
$string .= $chars[mt_rand(0, $max)];
}
return $string;
}
$HTTP_SESSION=_rand();
echo $HTTP_SESSION;
$HTTP_Server="www.baidu.com";
$HTTP_URL="/";
$ch = curl_init();
curl_setopt ($ch,CURLOPT_URL,"http://".$HTTP_Server.$HTTP_URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
//curl_setopt($ch,CURLOPT_COOKIE,$HTTP_SESSION);
$res = curl_exec($ch);
curl_close ($ch);
print_r($res);
?瘋?哄??浠g??锛?
1????cookies绋?搴?锛?
$URL="http://www.yoururl.com/bbs/login.asp?action=chk";
//濉??ヨ?哄?????婚??椤甸?㈠?闆??
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_REFERER,"http://www.hxfoods.com/bbs/login.asp");
//璁劇疆锛?璁塊??椤甸?㈢???ユ??闆??
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,'username=?????㈡?婚????&password=168168');
//?????婚??椤甸??????ㄦ?峰??锛?瀵???????瀵瑰?璧鋒?? curl_setopt ($ch, CURLOPT_HEADER,true);
//浣胯?芥?劇ずhttp澶達?
curl_exec($ch);
if (curl_errno($ch))
{
print curl_error($ch);
}
else
{
curl_close($ch);
}
2???鋒ゼ浜?锛?
set_time_limit(0);
//璁劇疆绋?搴??ц??堕?存?????? $i=10000;
//??10000娆? for($j=0;$j<$i;$j++)
{
$URL="http://www.yoururl.com/bbs/savepost.asp";
//杩?涓??闆??????澶?琛ㄥ??????ction??url?闆??
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_REFERER,"http://www.hxfoods.com/bbs/dispbbs.asp?boardid=14&replyid=672709&id=127437&page=1&skin=0&Star=53");
//璁劇疆?ユ??闆??锛?濡???涓?璁劇疆锛?璁哄?????″?ㄦ?????芥??楠?璇?涓???璁稿??澶?
curl_setopt($ch,CURLOPT_COOKIESESSION,true);
//?戒?瀛?cookie
curl_setopt($ch,CURLOPT_COOKIE,"DvForum=userid=24122&usercookies=0&userhidden=2&password=w0reu3g775VrY745&userclass=%96%7C&username=%A1%FA%A1%FA%B8%D2%CB%C0%B6%D3%A1%FA&StatUserID=2194783945 ");
//杩??垮氨??璁劇疆cookie浜?
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_NOBODY,1);
//涓??劇ず??瀹癸???涓烘??寰?澶?璁哄????澶???瑕????ㄨ煩杞???
curl_setopt($ch,CURLOPT_POSTFIELDS,'Body=gfdfgdfgasdfgdfgdfgdfg& followup=672709&RootID=127437&star=58&TotalUseTable=Dv_bbs3& amp;UserName=?????㈡?婚????&signflag=1&total=65535');
//??浣?????????澶?琛ㄥ???????闆????璧??? curl_setopt ($ch, CURLOPT_HEADER,true);
curl_exec($ch);
if (curl_errno($ch))
{
print curl_error($ch);
}
else
{
curl_close($ch);
}
}
curl_close ?? ?抽??涓?涓?curl浼?璇?
curl_copy_handle ?? ?瘋?涓?涓?curl杩??ヨ?婧?????????瀹瑰?????? curl_errno ?? 杩???涓?涓?????褰???浼?璇???璇?淇℃?????闆??缂??? curl_error ?? 杩???涓?涓?????褰???浼?璇???璇?淇℃????瀛?绗?覆
curl_exec ?? ?ц?涓?涓?curl浼?璇?
curl_getinfo ?? ?峰??涓?涓?curl杩??ヨ?婧??ユ????淇℃??
curl_init ?? ??濮???涓?涓?curl浼?璇?
curl_multi_add_handle ?? ??curl?瑰???浼?璇?涓?娣誨????????curl?ユ??璧?婧?
curl_multi_close ?? ?抽??涓?涓??瑰????ユ??璧?婧?
curl_multi_exec ?? 瑙f??涓?涓?curl?瑰????ユ??
curl_multi_getcontent ?? 杩????峰????杈??虹??????娴?
curl_multi_info_read ?? ?峰??褰???瑙f????curl???稿?充?杈?淇℃??
curl_multi_init ?? ??濮???涓?涓?curl?瑰????ユ??璧?婧?
curl_multi_remove_handle ?? 绉婚??url?瑰????ユ??璧?婧?涓?????涓??ユ??璧?婧?
curl_multi_select ?? Get all the sockets associated with the cURL extension, which can then be "selected"
curl_setopt_array ?? 浠ユ?扮???褰㈠?涓轟?涓?curl璁劇疆浼?璇????? curl_setopt ?? 涓轟?涓?curl璁劇疆浼?璇????? curl_version ?? ?峰??curl?稿?崇??????淇℃??
curl_init()?芥?扮??浣??ㄥ??濮???涓?涓?curl浼?璇?锛?curl_init()?芥?闆??涓???涓?涓????版????????锛?琛ㄧず涓?涓?url?闆????
curl_exec()?芥?扮??浣??ㄦ???ц?涓?涓?curl浼?璇?锛???涓??????版??curl_init()?芥?拌??????ユ????
curl_close()?芥?扮??浣??ㄦ???抽??涓?涓?curl浼?璇?锛???涓??????版??curl_init()?芥?拌??????ユ????
$ch = curl_init("http://www.baidu.com/");
curl_exec($ch);
curl_close($ch);
curl_version()?芥?扮??浣??ㄦ???峰??curl?稿?崇??????淇℃??锛?curl_version()?芥?版??涓?涓????幫?涓?娓?妤?????浠?涔???
print_r(curl_version())
curl_getinfo()?芥?扮??浣??ㄦ???峰??涓?涓?curl杩??ヨ?婧??ユ????淇℃??锛?curl_getinfo()?芥?版??涓や釜???幫?绗?涓?涓????版??curl??璧?婧??ユ??锛?绗?浜?涓????版??涓????浜?甯擱??锛?
$ch = curl_init("http://www.baidu.com/");
print_r(curl_getinfo($ch));
??????甯擱??????锛?
CURLINFO_EFFECTIVE_URL?????涓?涓???????url?闆??
CURLINFO_HTTP_CODE?????涓?涓??跺?扮??HTTP浠g??
CURLINFO_FILETIME?杩?绋??峰????妗g???堕?達?濡?????娉??峰??锛???杩????間負??-1??
CURLINFO_TOTAL_TIME?????涓?娆′?杈???娑??????堕??
CURLINFO_NAMELOOKUP_TIME???绉拌В????娑??????堕??
CURLINFO_CONNECT_TIME?寤虹??杩??ユ??娑??????堕??
CURLINFO_PRETRANSFER_TIME?浠?寤虹??杩??ュ?闆??澶?浼?杈???浣跨?ㄧ???堕??
CURLINFO_STARTTRANSFER_TIME?浠?寤虹??杩??ュ?頒?杈?寮?濮???浣跨?ㄧ???堕??
CURLINFO_REDIRECT_TIME??ㄤ??′?杈?寮?濮?????瀹?????浣跨?ㄧ???堕??
CURLINFO_SIZE_UPLOAD?涓?浼??版???????誨??
CURLINFO_SIZE_DOWNLOAD涓?杞芥?版???????誨??
CURLINFO_SPEED_DOWNLOAD骞沖??涓?杞介??搴?
CURLINFO_SPEED_UPLOAD骞沖??涓?浼???搴?
CURLINFO_HEADER_SIZE?header?ㄥ????澶у?
CURLINFO_HEADER_OUT????璇鋒???瀛?绗?覆
CURLINFO_REQUEST_SIZE??TTP璇鋒?涓?????棰???璇鋒???澶у?
CURLINFO_SSL_VERIFYRESULT
Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
CURLINFO_CONTENT_LENGTH_DOWNLOAD?浠?Content-Length: field涓?璇誨????涓?杞藉??瀹歸?垮害
CURLINFO_CONTENT_LENGTH_UPLOAD涓?浼???瀹瑰ぇ灏???璇存??
CURLINFO_CONTENT_TYPE?涓?杞藉??瀹圭????Content-type???鹼?NULL琛ㄧず???″?ㄦ病??????????????Content-Type: header??
curl_setopt()?芥?扮??浣??ㄦ??涓轟?涓?curl璁劇疆浼?璇????般??curl_setopt_array()?芥?扮??浣??ㄦ??浠ユ?扮???褰㈠?涓轟?涓?curl璁劇疆浼?璇????般??
$ch = curl_init();
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
$options = array(
CURLOPT_URL => ??http://www.baidu.com/??,
CURLOPT_HEADER => false
);
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
fclose($fp);
??璁劇疆?????版??锛?
CURLOPT_AUTOREFERER
???ㄨ?劇疆header涓???referer淇℃??
CURLOPT_BINARYTRANSFER
?ㄥ????URLOPT_RETURNTRANSFER?跺??灏??峰???版??杩???
CURLOPT_COOKIESESSION
???ㄦ??url浼?浠?浠?浼???涓?涓?session cookie锛?蹇界?ュ?朵???cookie锛?榛?璁ょ?跺?典?curl浼?灏???????cookie杩???缁????$????session cookie?????d??ㄦ?ュ?ゆ?????″?ㄧ????session??????????瀛??ㄧ??cookie??
CURLOPT_CRLF
???ㄦ?跺?Unix???㈣?绗?漿?㈡????杞??㈣?绗???
CURLOPT_DNS_USE_GLOBAL_CACHE
???ㄦ?朵????ㄤ?涓??ㄥ???DNS缂?瀛?锛?姝ら」涓虹嚎绋?瀹??ㄧ??锛?骞朵?榛?璁や負true??
CURLOPT_FAILONERROR
?劇ずHTTP?舵????锛?榛?璁よ?涓烘??蹇界?ョ??峰?浜?绛?浜?400??HTTP淇℃??
CURLOPT_FILETIME
???ㄦ?朵?灏?璇?淇??矽?绋???妗d腑??淇℃????缁???淇℃??浼???杩?curl_getinfo()?芥?扮??CURLINFO_FILETIME??椤矽?????
CURLOPT_FOLLOWLOCATION
???ㄦ?朵?灏????″?ㄦ???″?ㄨ???????Location:???懼??eader涓???褰???杩???缁????″???浣跨??URLOPT_MAXREDIRS??浠ラ??瀹???褰?杩??????伴????
CURLOPT_FORBID_REUSE
?ㄥ????浜や?浠ュ??寮鴻揩??寮?杩??ワ?涓??介???ㄣ??
CURLOPT_FRESH_CONNECT
寮哄?惰?峰??涓?涓??扮??杩??ワ??誇唬缂?瀛?涓???杩??ャ??
CURLOPT_FTP_USE_EPRT
TRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and LPRT and use PORT only.
Added in PHP 5.0.0.
CURLOPT_FTP_USE_EPSV
TRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to disable EPSV.
CURLOPT_FTPAPPEND
TRUE to append to the remote file instead of overwriting it.
CURLOPT_FTPASCII
An alias of CURLOPT_TRANSFERTEXT. Use that instead.
CURLOPT_FTPLISTONLY
TRUE to only list the names of an FTP directory.
CURLOPT_HEADER
???ㄦ?朵?灏?澶存??浠剁??淇℃??浣?涓烘?版??娴?杈??恒??
CURLOPT_HTTPGET
???ㄦ?朵?璁劇疆HTTP??method涓?ET锛???涓?ET??榛?璁ゆ??锛???浠ュ???ㄨ?淇??圭?????典?浣跨?ㄣ??
CURLOPT_HTTPPROXYTUNNEL
???ㄦ?朵???杩?HTTP浠g???ヤ?杈???
CURLOPT_MUTE
璁?url?芥?頒腑????淇??矽??????版?㈠?榛?璁ゅ?箋??
CURLOPT_NETRC
?ㄨ??ュ緩绔?浠ュ??锛?璁塊??~/.netrc??浠惰?峰???ㄦ?峰????瀵???淇℃??杩??ヨ?绋?绔??廣??
CURLOPT_NOBODY
???ㄦ?跺?涓?瀵?TML涓???body?ㄥ??杩?琛?杈??恒??
CURLOPT_NOPROGRESS
???ㄦ?跺?抽??curl浼?杈???杩?搴??★?姝ら」??榛?璁よ?劇疆涓?rue
CURLOPT_NOSIGNAL
???ㄦ?跺拷?ユ??????curl浼???缁?php杩?琛???淇″?楓????API澶?绾跨?浼?杈??舵?ら」琚?榛?璁ゆ??寮???
CURLOPT_POST
???ㄦ?朵?????涓?涓?甯歌???POST璇鋒?锛?绫誨??涓猴?application/x-www-form-urlencoded锛?灏卞??琛ㄥ????浜ょ??涓??楓??
CURLOPT_PUT
???ㄦ?跺??璁?TTP??????浠訛?蹇?椤誨???惰?劇疆CURLOPT_INFILE??CURLOPT_INFILESIZE
CURLOPT_RETURNTRANSFER
璁?url_exec()?峰????淇℃??浠ユ??浠舵???褰㈠?杩???锛???涓????存?ヨ??恒??
CURLOPT_SSL_VERIFYPEER
FALSE to stop cURL from verifying the peer??s certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2). TRUE by default as of cURL 7.10. Default bundle installed as of cURL 7.10.
CURLOPT_TRANSFERTEXT
TRUE to use ASCII mode for FTP transfers. For LDAP, it retrieves data in plain text instead of HTML. On Windows systems, it will not set STDOUT to binary mode.
CURLOPT_UNRESTRICTED_AUTH
?ㄤ嬌??URLOPT_FOLLOWLOCATION浜х????header涓???澶?涓?locations涓???缁?杩藉???ㄦ?峰????瀵???淇℃??锛??充嬌????宸插?????瑰????
CURLOPT_UPLOAD
???ㄦ?跺??璁告??浠朵?杈?
CURLOPT_VERBOSE
???ㄦ?朵?姹??ユ??????淇℃??锛?瀛??懼??TDERR????瀹???CURLOPT_STDERR涓?
CURLOPT_BUFFERSIZE
姣?娆¤?峰?????版??涓?璇誨?ョ?瀛???澶у?锛?杩?涓??兼??娆¢?戒?琚?濉?婊°??
CURLOPT_CLOSEPOLICY
涓???CURLCLOSEPOLICY_LEAST_RECENTLY_USED灏辨??CURLCLOSEPOLICY_OLDEST锛?杩?瀛??ㄥ???涓?涓?锛?浣???curl???惰?涓???????.
CURLOPT_CONNECTTIMEOUT
?ㄥ??璧瘋??ュ??绛?寰????堕?達?濡???璁劇疆涓?锛???涓?绛?寰???
CURLOPT_DNS_CACHE_TIMEOUT
璁劇疆?ㄥ??瀛?涓?淇?瀛?DNS淇℃?????堕?達?榛?璁や負120绉???
CURLOPT_FTPSSLAUTH
The FTP authentication method (when is activated): CURLFTPAUTH_SSL (try SSL first), CURLFTPAUTH_TLS (try TLS first), or CURLFTPAUTH_DEFAULT (let cURL decide).
CURLOPT_HTTP_VERSION
璁劇疆curl浣跨?ㄧ??HTTP??璁?锛?CURL_HTTP_VERSION_NONE锛?璁?url??宸卞?ゆ??锛?锛?CURL_HTTP_VERSION_1_0锛?HTTP/1.0锛?锛?CURL_HTTP_VERSION_1_1锛?HTTP/1.1锛?
CURLOPT_HTTPAUTH
浣跨?ㄧ??HTTP楠?璇??規?锛????????兼??锛?CURLAUTH_BASIC锛?CURLAUTH_DIGEST锛?CURLAUTH_GSSNEGOTIATE锛?CURLAUTH_NTLM锛?CURLAUTH_ANY锛?CURLAUTH_ANYSAFE锛???浠ヤ嬌?ㄢ??|????浣?绗?????澶?涓??鹼?curl璁╂???″?ㄩ???╀?涓???????濂界???鹼?CURLAUTH_ANY绛?浠蜂?CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM锛?CURLAUTH_ANYSAFE绛?浠蜂?CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM
CURLOPT_INFILESIZE
璁懼??涓?浼???浠剁??澶у?
CURLOPT_LOW_SPEED_LIMIT
褰?浼?杈???搴??浜?CURLOPT_LOW_SPEED_LIMIT?訛?PHP浼??規??CURLOPT_LOW_SPEED_TIME?ュ?ゆ????????澶??㈣????娑?浼?杈???
CURLOPT_LOW_SPEED_TIME
The number of seconds the transfer should be below CURLOPT_LOW_SPEED_LIMIT for PHP to consider the transfer too slow and abort.
褰?浼?杈???搴??浜?CURLOPT_LOW_SPEED_LIMIT?訛?PHP浼??規??CURLOPT_LOW_SPEED_TIME?ュ?ゆ????????澶??㈣????娑?浼?杈???
CURLOPT_MAXCONNECTS
??璁哥????澶ц??ユ?伴??锛?瓒?杩???浼???杩?CURLOPT_CLOSEPOLICY?沖??搴?璇ュ??姝㈠??浜?杩???
CURLOPT_MAXREDIRS
??瀹???澶???HTTP??瀹??????伴??锛?杩?涓???椤規????CURLOPT_FOLLOWLOCATION涓?璧蜂嬌?ㄧ????
CURLOPT_PORT
涓?涓????????ㄦ?ユ??瀹?杩??ョ???g????
CURLOPT_PROXYAUTH
The HTTP authentication method(s) to use for the proxy connection. Use the same bitmasks as described in CURLOPT_HTTPAUTH. For proxy authentication, only CURLAUTH_BASIC and CURLAUTH_NTLM are currently supported.
CURLOPT_PROXYPORT
The port number of the proxy to connect to. This port number can also be set in CURLOPT_PROXY.
CURLOPT_PROXYTYPE
Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5.
CURLOPT_RESUME_FROM
?ㄦ?㈠?浼?杈??朵???涓?涓?瀛?????绉婚??锛??ㄦ?ユ???圭畫浼?锛?
CURLOPT_SSL_VERIFYHOST
1 to check the existence of a common name in the SSL peer certificate.
2 to check the existence of a common name and also verify that it matches the hostname provided.
CURLOPT_SSLVERSION
The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases this must be set manually.
CURLOPT_TIMECONDITION
濡?????URLOPT_TIMEVALUE??瀹?????涓??堕?翠互??琚?缂?杈?杩?锛???浣跨??URL_TIMECOND_IFMODSINCE杩???椤甸???濡???娌℃??琚?淇??矽?锛?骞朵?CURLOPT_HEADER涓?rue锛???杩???涓?涓???304 Not Modified????header锛?CURLOPT_HEADER涓?alse锛???浣跨??URL_TIMECOND_ISUNMODSINCE锛?榛?璁ゅ?間負 CURL_TIMECOND_IFMODSINCE
CURLOPT_TIMEOUT
璁劇疆curl??璁告?ц??????跨???
CURLOPT_TIMEVALUE
璁劇疆涓?涓?CURLOPT_TIMECONDITION浣跨?ㄧ???堕?存?籌??ㄩ?璁ょ?舵??涓?浣跨?ㄧ????CURL_TIMECOND_IFMODSINCE
CURLOPT_CAINFO
The name of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with CURLOPT_SSL_VERIFYPEER.
CURLOPT_CAPATH
A directory that holds multiple CA certificates. Use this option alongside CURLOPT_SSL_VERIFYPEER.
CURLOPT_COOKIE
璁懼??HTTP璇鋒?涓???Set-Cookie:???ㄥ??????瀹廣??
CURLOPT_COOKIEFILE
????cookie淇℃??????浠跺??绉幫?杩?涓?cookie??浠跺??浠ユ??Netscape?煎?????HTTP椋??肩??header淇℃????
CURLOPT_COOKIEJAR
杩??ュ?抽??浠ュ??锛?瀛???ookie淇℃??????浠跺??绉?
CURLOPT_CUSTOMREQUEST
A custom request method to use instead of ??GET?? or ??HEAD?? when doing a HTTP request. This is useful for doing ??DELETE?? or other, more obscure HTTP requests. Valid values are things like ??GET??, ??POST??, ??CONNECT?? and so on; i.e. Do not enter a whole HTTP request line here. For instance, entering ??GET /index.html HTTP/1.0\r\n\r\n?? would be incorrect.
Note: Don??t do this without making sure the server supports the custom request method first.
CURLOPT_EGBSOCKET
Like CURLOPT_RANDOM_FILE, except a filename to an Entropy Gathering Daemon socket.
CURLOPT_ENCODING
header涓???Accept-Encoding: ???ㄥ??????瀹癸???????缂????煎?涓猴???identity??锛???deflate??锛???gzip????濡???璁劇疆涓虹┖瀛?绗?覆锛???琛ㄧず??????????缂????煎?
CURLOPT_FTPPORT
The value which will be used to get the IP address to use for the FTP ??POST?? instruction. The ??POST?? instruction tells the remote server to connect to our specified IP address. The string may be a plain IP address, a hostname, a network interface name (under Unix), or just a plain ??-?? to use the systems default IP address.
CURLOPT_INTERFACE
?ㄥ??ㄧ?缁??ュ?d腑浣跨?ㄧ????绉幫???浠ユ??涓?涓??ュ?e??锛?IP????涓繪?哄????
CURLOPT_KRB4LEVEL
KRB4(Kerberos 4)瀹??ㄧ駭????璁劇疆锛???浠ユ??涓?涓???涓??間?涓?锛???clear??锛???safe??锛???confidential??锛???private????榛?璁ょ???間負??private??锛?璁劇疆涓?ull???跺??琛ㄧず绂???RB4锛??闆??RB4瀹??ㄤ??藉??TP浼?杈?涓?浣跨?ㄣ??
CURLOPT_POSTFIELDS
??TTP涓?????POST????浣???濡???瑕?浼???涓?涓???浠訛???瑕?涓?涓?@寮?澶寸????浠跺??
CURLOPT_PROXY
璁劇疆??杩???HTTP浠g?????″??
CURLOPT_PROXYUSERPWD
杩??ュ?頒唬?????″?ㄧ??锛??煎?涓衡??[username]:[password]?????ㄦ?峰????瀵?????
CURLOPT_RANDOM_FILE
璁懼??瀛???SL?ㄥ?扮?????烘?扮?瀛?????浠跺??绉?
CURLOPT_RANGE
璁劇疆HTTP浼?杈????達???浠ョ?ㄢ??X-Y????褰㈠?璁劇疆涓?涓?浼?杈??洪?達?濡?????澶?涓?HTTP浼?杈?锛???浣跨?ㄩ???峰????澶?涓??鹼?褰㈠?锛???X-Y,N-M????
CURLOPT_REFERER
璁劇疆header涓???Referer: ?? ?ㄥ?????箋??
CURLOPT_SSL_CIPHER_LIST
A list of ciphers to use for SSL. For example, RC4-SHA and TLSv1 are valid cipher lists.
CURLOPT_SSLCERT
浼???涓?涓?????PEM?煎?璇?涔???瀛?绗?覆??
CURLOPT_SSLCERTPASSWD
浼???涓?涓?????浣跨??URLOPT_SSLCERT璇?涔??????瀵?????
CURLOPT_SSLCERTTYPE
The format of the certificate. Supported formats are ??PEM?? (default), ??DER??, and ??ENG??.
CURLOPT_SSLENGINE
The identifier for the crypto engine of the private SSL key specified in CURLOPT_SSLKEY.
CURLOPT_SSLENGINE_DEFAULT
The identifier for the crypto engine used for asymmetric crypto operations.
CURLOPT_SSLKEY
The name of a file containing a private SSL key.
CURLOPT_SSLKEYPASSWD
The secret password needed to use the private SSL key specified in CURLOPT_SSLKEY.
Note: Since this option contains a sensitive password, remember to keep the PHP script it is contained within safe.
CURLOPT_SSLKEYTYPE
The key type of the private SSL key specified in CURLOPT_SSLKEY. Supported key types are ??PEM?? (default), ??DER??, and ??ENG??.
CURLOPT_URL
??瑕??峰????URL?闆??锛?涔???浠ュ??HP??curl_init()?芥?頒腑璁劇疆??
CURLOPT_USERAGENT
??TTP璇鋒?涓?????涓?涓???user-agent??澶寸??瀛?绗?覆??
CURLOPT_USERPWD
浼???涓?涓?杩??ヤ腑??瑕????ㄦ?峰????瀵???锛??煎?涓猴???[username]:[password]????
CURLOPT_HTTP200ALIASES
璁劇疆涓???浠?rror??褰㈠??ュ???HTTP 200????搴?锛??煎?涓轟?涓??扮???
CURLOPT_HTTPHEADER
璁劇疆涓?涓?header涓?浼?杈???瀹圭???扮???
CURLOPT_POSTQUOTE
An array of FTP commands to execute on the server after the FTP request has been performed.
CURLOPT_QUOTE
An array of FTP commands to execute on the server prior to the FTP request.
CURLOPT_FILE
璁劇疆杈??烘??浠剁??浣?缃?锛??兼??涓?涓?璧?婧?绫誨??锛?榛?璁や負STDOUT (娴?瑙?????
CURLOPT_INFILE
?ㄤ?浼???浠剁???跺????瑕?璇誨??????浠跺?闆??锛??兼??涓?涓?璧?婧?绫誨????
CURLOPT_STDERR
璁劇疆涓?涓???璇?杈??哄?闆??锛??兼??涓?涓?璧?婧?绫誨??锛???浠i?璁ょ??STDERR??
CURLOPT_WRITEHEADER
璁劇疆header?ㄥ????瀹圭?????ョ????浠跺?闆??锛??兼??涓?涓?璧?婧?绫誨????
CURLOPT_HEADERFUNCTION
璁劇疆涓?涓???璋??芥?幫?杩?涓??芥?版??涓や釜???幫?绗?涓?涓???curl??璧?婧??ユ??锛?绗?浜?涓???杈??虹??header?版????header?版????杈??哄?椤諱?璧?杩?涓??芥?幫?杩???宸插???ョ???版??澶у???
CURLOPT_PASSWDFUNCTION
璁劇疆涓?涓???璋??芥?幫???涓?涓????幫?绗?涓?涓???curl??璧?婧??ユ??锛?绗?浜?涓???涓?涓?瀵?????绀虹???绗?涓?涓????版??瀵????垮害??璁哥????澶у?箋??杩???瀵??????箋??
CURLOPT_READFUNCTION
璁劇疆涓?涓???璋??芥?幫???涓や釜???幫?绗?涓?涓???curl??璧?婧??ユ??锛?绗?浜?涓???璇誨???扮???版?????版??璇誨??蹇?椤諱?璧?杩?涓??芥?般??杩???璇誨???版????澶у?锛?姣?濡?0????EOF??
CURLOPT_WRITEFUNCTION
璁劇疆涓?涓???璋??芥?幫???涓や釜???幫?绗?涓?涓???curl??璧?婧??ユ??锛?绗?浜?涓??????ョ???版?????版?????ュ?椤諱?璧?杩?涓??芥?般??杩???绮劇‘??宸插???ユ?版????澶у?
curl_copy_handle()?芥?扮??浣??ㄦ???瘋?涓?涓?curl杩??ヨ?婧?????????瀹瑰??????
$ch = curl_init(??http://www.baidu.com/??);
$another = curl_copy_handle($ch);
curl_exec($another);
curl_close($another);
curl_error()?芥?扮??浣??ㄦ??杩???涓?涓?????褰???浼?璇???璇?淇℃????瀛?绗?覆??
curl_errno()?芥?扮??浣??ㄦ??杩???涓?涓?????褰???浼?璇???璇?淇℃?????闆??缂??楓??
curl_multi_init()?芥?扮??浣??ㄦ????濮???涓?涓?curl?瑰????ユ??璧?婧???
curl_multi_add_handle()?芥?扮??浣??ㄦ????curl?瑰???浼?璇?涓?娣誨????????curl?ユ??璧?婧???curl_multi_add_handle()?芥?版??涓や釜???幫?绗?涓?涓????拌〃绀轟?涓?curl?瑰????ユ??璧?婧?锛?绗?浜?涓????拌〃绀轟?涓???????curl?ユ??璧?婧???
curl_multi_exec()?芥?扮??浣??ㄦ??瑙f??涓?涓?curl?瑰????ユ??锛?curl_multi_exec()?芥?版??涓や釜???幫?绗?涓?涓????拌〃绀轟?涓??瑰????ユ??璧?婧?锛?绗?浜?涓????版??涓?涓?寮??ㄥ?肩?????幫?琛ㄧず?╀???瑕?澶???????涓???curl?ユ??璧?婧??伴????
curl_multi_remove_handle()?芥?拌〃绀虹Щ??url?瑰????ユ??璧?婧?涓?????涓??ユ??璧?婧?锛?curl_multi_remove_handle()?芥?版??涓や釜???幫?绗?涓?涓????拌〃绀轟?涓?curl?瑰????ユ??璧?婧?锛?绗?浜?涓????拌〃绀轟?涓???????curl?ユ??璧?婧???
curl_multi_close()?芥?扮??浣??ㄦ???抽??涓?涓??瑰????ユ??璧?婧???
$ch1 = curl_init();
$ch2 = curl_init();
curl_setopt($ch1, CURLOPT_URL, ??http://www.baidu.com/??);
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, ??http://www.google.com/??);
curl_setopt($ch2, CURLOPT_HEADER, 0);
$mh = curl_multi_init();
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
do {
curl_multi_exec($mh,$flag);
} while ($flag > 0);
curl_multi_remove_handle($mh,$ch1);
curl_multi_remove_handle($mh,$ch2);
curl_multi_close($mh);
curl_multi_getcontent()?芥?扮??浣??ㄦ???ㄨ?劇疆浜?CURLOPT_RETURNTRANSFER?????典?锛?杩????峰????杈??虹??????娴???
curl_multi_info_read()?芥?扮??浣??ㄦ???峰??褰???瑙f????curl???稿?充?杈?淇℃????
curl_multi_select()
Get all the sockets associated with the cURL extension, which can then be ??selected??
source url:http://www.hebaodans.com/2009/07/p-h-p-c-u-r-l-yong-fa/
HTTP request method PUT
//a.php
<?php
if($_SERVER['REQUEST_METHOD'] == 'PUT')
{
parse_str(file_get_contents('php://input'), $requestData);
// Array ( [foo] => bar )
echo json_encode($requestData);
// Do something with data...
}
//curl.php
<?php
$array = array('a'=>1,'b'=>2);
function doPut($url, $fields)
{
$fields = (is_array($fields)) ? http_build_query($fields) : $fields;
if($ch = curl_init($url))
{
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($fields)));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$rs=curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $rs;
}
else
{
return false;
}
}
echo doPut('http://127.1/a.php',$array);
?ユ??DELETE?規?锛?????????PUT?逛負DELETE?規??沖????
php curl class:
<?php
/**
* cURL class
*
* This is a wrapper class for curl, it is quite easy to use:
* <code>
* $c = new curl;
* // enable cache
* $c = new curl(array('cache'=>true));
* // enable cookie
* $c = new curl(array('cookie'=>true));
* // enable proxy
* $c = new curl(array('proxy'=>true));
*
* // HTTP GET Method
* $html = $c->get('http://example.com');
* // HTTP POST Method
* $html = $c->post('http://example.com/', array('q'=>'words', 'name'=>'moodle'));
* // HTTP PUT Method
* $html = $c->put('http://example.com/', array('file'=>'/var/www/test.txt');
* </code>
*
* @author Dongsheng Cai <[email?protected]> - https://github.com/dongsheng/cURL
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class curl {
/** @var bool */
public $cache = false;
public $proxy = false;
/** @var array */
public $response = array();
public $header = array();
/** @var string */
public $info;
public $error;
/** @var array */
private $options;
/** @var string */
private $proxy_host = '';
private $proxy_auth = '';
private $proxy_type = '';
/** @var bool */
private $debug = false;
private $cookie = false;
/**
* @param array $options
*/
public function __construct($options = array()){
if (!function_exists('curl_init')) {
$this->error = 'cURL module must be enabled!';
trigger_error($this->error, E_USER_ERROR);
return false;
}
// the options of curl should be init here.
$this->resetopt();
if (!empty($options['debug'])) {
$this->debug = true;
}
if(!empty($options['cookie'])) {
if($options['cookie'] === true) {
$this->cookie = 'curl_cookie.txt';
} else {
$this->cookie = $options['cookie'];
}
}
if (!empty($options['cache'])) {
if (class_exists('curl_cache')) {
$this->cache = new curl_cache();
}
}
}
/**
* Resets the CURL options that have already been set
*/
public function resetopt(){
$this->options = array();
$this->options['CURLOPT_USERAGENT'] = 'MoodleBot/1.0';
// True to include the header in the output
$this->options['CURLOPT_HEADER'] = 0;
// True to Exclude the body from the output
$this->options['CURLOPT_NOBODY'] = 0;
// TRUE to follow any "Location: " header that the server
// sends as part of the HTTP header (note this is recursive,
// PHP will follow as many "Location: " headers that it is sent,
// unless CURLOPT_MAXREDIRS is set).
//$this->options['CURLOPT_FOLLOWLOCATION'] = 1;
$this->options['CURLOPT_MAXREDIRS'] = 10;
$this->options['CURLOPT_ENCODING'] = '';
// TRUE to return the transfer as a string of the return
// value of curl_exec() instead of outputting it out directly.
$this->options['CURLOPT_RETURNTRANSFER'] = 1;
$this->options['CURLOPT_BINARYTRANSFER'] = 0;
$this->options['CURLOPT_SSL_VERIFYPEER'] = 0;
$this->options['CURLOPT_SSL_VERIFYHOST'] = 2;
$this->options['CURLOPT_CONNECTTIMEOUT'] = 30;
}
/**
* Reset Cookie
*/
public function resetcookie() {
if (!empty($this->cookie)) {
if (is_file($this->cookie)) {
$fp = fopen($this->cookie, 'w');
if (!empty($fp)) {
fwrite($fp, '');
fclose($fp);
}
}
}
}
/**
* Set curl options
*
* @param array $options If array is null, this function will
* reset the options to default value.
*
*/
public function setopt($options = array()) {
if (is_array($options)) {
foreach($options as $name => $val){
if (stripos($name, 'CURLOPT_') === false) {
$name = strtoupper('CURLOPT_'.$name);
}
$this->options[$name] = $val;
}
}
}
/**
* Reset http method
*
*/
public function cleanopt(){
unset($this->options['CURLOPT_HTTPGET']);
unset($this->options['CURLOPT_POST']);
unset($this->options['CURLOPT_POSTFIELDS']);
unset($this->options['CURLOPT_PUT']);
unset($this->options['CURLOPT_INFILE']);
unset($this->options['CURLOPT_INFILESIZE']);
unset($this->options['CURLOPT_CUSTOMREQUEST']);
}
/**
* Set HTTP Request Header
*
* @param array $headers
*
*/
public function setHeader($header) {
if (is_array($header)){
foreach ($header as $v) {
$this->setHeader($v);
}
} else {
$this->header[] = $header;
}
}
/**
* Set HTTP Response Header
*
*/
public function getResponse(){
return $this->response;
}
/**
* private callback function
* Formatting HTTP Response Header
*
* @param mixed $ch Apparently not used
* @param string $header
* @return int The strlen of the header
*/
private function formatHeader($ch, $header)
{
$this->count++;
if (strlen($header) > 2) {
list($key, $value) = explode(" ", rtrim($header, "\r\n"), 2);
$key = rtrim($key, ':');
if (!empty($this->response[$key])) {
if (is_array($this->response[$key])){
$this->response[$key][] = $value;
} else {
$tmp = $this->response[$key];
$this->response[$key] = array();
$this->response[$key][] = $tmp;
$this->response[$key][] = $value;
}
} else {
$this->response[$key] = $value;
}
}
return strlen($header);
}
/**
* Set options for individual curl instance
*
* @param object $curl A curl handle
* @param array $options
* @return object The curl handle
*/
private function apply_opt($curl, $options) {
// Clean up
$this->cleanopt();
// set cookie
if (!empty($this->cookie) || !empty($options['cookie'])) {
$this->setopt(array('cookiejar'=>$this->cookie,
'cookiefile'=>$this->cookie
));
}
// set proxy
if (!empty($this->proxy) || !empty($options['proxy'])) {
$this->setopt($this->proxy);
}
$this->setopt($options);
// reset before set options
curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this,'formatHeader'));
// set headers
if (empty($this->header)){
$this->setHeader(array(
'User-Agent: MoodleBot/1.0',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Connection: keep-alive'
));
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->header);
if ($this->debug){
echo '<h1>Options</h1>';
var_dump($this->options);
echo '<h1>Header</h1>';
var_dump($this->header);
}
// set options
foreach($this->options as $name => $val) {
if (is_string($name)) {
$name = constant(strtoupper($name));
}
curl_setopt($curl, $name, $val);
}
return $curl;
}
/**
* Download multiple files in parallel
*
* Calls {@link multi()} with specific download headers
*
* <code>
* $c = new curl;
* $c->download(array(
* array('url'=>'http://localhost/', 'file'=>fopen('a', 'wb')),
* array('url'=>'http://localhost/20/', 'file'=>fopen('b', 'wb'))
* ));
* </code>
*
* @param array $requests An array of files to request
* @param array $options An array of options to set
* @return array An array of results
*/
public function download($requests, $options = array()) {
$options['CURLOPT_BINARYTRANSFER'] = 1;
$options['RETURNTRANSFER'] = false;
return $this->multi($requests, $options);
}
/*
* Mulit HTTP Requests
* This function could run multi-requests in parallel.
*
* @param array $requests An array of files to request
* @param array $options An array of options to set
* @return array An array of results
*/
protected function multi($requests, $options = array()) {
$count = count($requests);
$handles = array();
$results = array();
$main = curl_multi_init();
for ($i = 0; $i < $count; $i++) {
$url = $requests[$i];
foreach($url as $n=>$v){
$options[$n] = $url[$n];
}
$handles[$i] = curl_init($url['url']);
$this->apply_opt($handles[$i], $options);
curl_multi_add_handle($main, $handles[$i]);
}
$running = 0;
do {
curl_multi_exec($main, $running);
} while($running > 0);
for ($i = 0; $i < $count; $i++) {
if (!empty($options['CURLOPT_RETURNTRANSFER'])) {
$results[] = true;
} else {
$results[] = curl_multi_getcontent($handles[$i]);
}
curl_multi_remove_handle($main, $handles[$i]);
}
curl_multi_close($main);
return $results;
}
/**
* Single HTTP Request
*
* @param string $url The URL to request
* @param array $options
* @return bool
*/
protected function request($url, $options = array()){
// create curl instance
$curl = curl_init($url);
$options['url'] = $url;
$this->apply_opt($curl, $options);
if ($this->cache && $ret = $this->cache->get($this->options)) {
return $ret;
} else {
$ret = curl_exec($curl);
if ($this->cache) {
$this->cache->set($this->options, $ret);
}
}
$this->info = curl_getinfo($curl);
$this->error = curl_error($curl);
if ($this->debug){
echo '<h1>Return Data</h1>';
var_dump($ret);
echo '<h1>Info</h1>';
var_dump($this->info);
echo '<h1>Error</h1>';
var_dump($this->error);
}
curl_close($curl);
if (empty($this->error)){
return $ret;
} else {
return $this->error;
// exception is not ajax friendly
//throw new moodle_exception($this->error, 'curl');
}
}
/**
* HTTP HEAD method
*
* @see request()
*
* @param string $url
* @param array $options
* @return bool
*/
public function head($url, $options = array()){
$options['CURLOPT_HTTPGET'] = 0;
$options['CURLOPT_HEADER'] = 1;
$options['CURLOPT_NOBODY'] = 1;
return $this->request($url, $options);
}
/**
* Recursive function formating an array in POST parameter
* @param array $arraydata - the array that we are going to format and add into &$data array
* @param string $currentdata - a row of the final postdata array at instant T
* when finish, it's assign to $data under this format: name[keyname][][]...[]='value'
* @param array $data - the final data array containing all POST parameters : 1 row = 1 parameter
*/
function format_array_postdata_for_curlcall($arraydata, $currentdata, &$data) {
foreach ($arraydata as $k=>$v) {
$newcurrentdata = $currentdata;
if (is_object($v)) {
$v = (array) $v;
}
if (is_array($v)) { //the value is an array, call the function recursively
$newcurrentdata = $newcurrentdata.'['.urlencode($k).']';
$this->format_array_postdata_for_curlcall($v, $newcurrentdata, $data);
} else { //add the POST parameter to the $data array
$data[] = $newcurrentdata.'['.urlencode($k).']='.urlencode($v);
}
}
}
/**
* Transform a PHP array into POST parameter
* (see the recursive function format_array_postdata_for_curlcall)
* @param array $postdata
* @return array containing all POST parameters (1 row = 1 POST parameter)
*/
function format_postdata_for_curlcall($postdata) {
if (is_object($postdata)) {
$postdata = (array) $postdata;
}
$data = array();
foreach ($postdata as $k=>$v) {
if (is_object($v)) {
$v = (array) $v;
}
if (is_array($v)) {
$currentdata = urlencode($k);
$this->format_array_postdata_for_curlcall($v, $currentdata, $data);
} else {
$data[] = urlencode($k).'='.urlencode($v);
}
}
$convertedpostdata = implode('&', $data);
return $convertedpostdata;
}
/**
* HTTP POST method
*
* @param string $url
* @param array|string $params
* @param array $options
* @return bool
*/
public function post($url, $params = '', $options = array()){
$options['CURLOPT_POST'] = 1;
if (is_array($params)) {
$params = $this->format_postdata_for_curlcall($params);
}
$options['CURLOPT_POSTFIELDS'] = $params;
return $this->request($url, $options);
}
/**
* HTTP GET method
*
* @param string $url
* @param array $params
* @param array $options
* @return bool
*/
public function get($url, $params = array(), $options = array()){
$options['CURLOPT_HTTPGET'] = 1;
if (!empty($params)){
$url .= (stripos($url, '?') !== false) ? '&' : '?';
$url .= http_build_query($params, '', '&');
}
return $this->request($url, $options);
}
/**
* HTTP PUT method
*
* @param string $url
* @param array $params
* @param array $options
* @return bool
*/
public function put($url, $params = array(), $options = array()){
$file = $params['file'];
if (!is_file($file)){
return null;
}
$fp = fopen($file, 'r');
$size = filesize($file);
$options['CURLOPT_PUT'] = 1;
$options['CURLOPT_INFILESIZE'] = $size;
$options['CURLOPT_INFILE'] = $fp;
if (!isset($this->options['CURLOPT_USERPWD'])){
$this->setopt(array('CURLOPT_USERPWD'=>'anonymous: [email?protected]'));
}
$ret = $this->request($url, $options);
fclose($fp);
return $ret;
}
/**
* HTTP DELETE method
*
* @param string $url
* @param array $params
* @param array $options
* @return bool
*/
public function delete($url, $param = array(), $options = array()){
$options['CURLOPT_CUSTOMREQUEST'] = 'DELETE';
if (!isset($options['CURLOPT_USERPWD'])) {
$options['CURLOPT_USERPWD'] = 'anonymous: [email?protected]';
}
$ret = $this->request($url, $options);
return $ret;
}
/**
* HTTP TRACE method
*
* @param string $url
* @param array $options
* @return bool
*/
public function trace($url, $options = array()){
$options['CURLOPT_CUSTOMREQUEST'] = 'TRACE';
$ret = $this->request($url, $options);
return $ret;
}
/**
* HTTP OPTIONS method
*
* @param string $url
* @param array $options
* @return bool
*/
public function options($url, $options = array()){
$options['CURLOPT_CUSTOMREQUEST'] = 'OPTIONS';
$ret = $this->request($url, $options);
return $ret;
}
public function get_info() {
return $this->info;
}
}
/**
* This class is used by cURL class, use case:
*
* <code>
*
* $c = new curl(array('cache'=>true), 'module_cache'=>'repository');
* $ret = $c->get('http://www.google.com');
* </code>
*
* @package core
* @subpackage file
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class curl_cache {
/** @var string */
public $dir = '';
/**
*
* @param string @module which module is using curl_cache
*
*/
function __construct() {
$this->dir = '/tmp/';
if (!file_exists($this->dir)) {
mkdir($this->dir, 0700, true);
}
$this->ttl = 1200;
}
/**
* Get cached value
*
* @param mixed $param
* @return bool|string
*/
public function get($param){
$this->cleanup($this->ttl);
$filename = 'u_'.md5(serialize($param));
if(file_exists($this->dir.$filename)) {
$lasttime = filemtime($this->dir.$filename);
if(time()-$lasttime > $this->ttl)
{
return false;
} else {
$fp = fopen($this->dir.$filename, 'r');
$size = filesize($this->dir.$filename);
$content = fread($fp, $size);
return unserialize($content);
}
}
return false;
}
/**
* Set cache value
*
* @param mixed $param
* @param mixed $val
*/
public function set($param, $val){
$filename = 'u_'.md5(serialize($param));
$fp = fopen($this->dir.$filename, 'w');
fwrite($fp, serialize($val));
fclose($fp);
}
/**
* Remove cache files
*
* @param int $expire The number os seconds before expiry
*/
public function cleanup($expire){
if($dir = opendir($this->dir)){
while (false !== ($file = readdir($dir))) {
if(!is_dir($file) && $file != '.' && $file != '..') {
$lasttime = @filemtime($this->dir.$file);
if(time() - $lasttime > $expire){
@unlink($this->dir.$file);
}
}
}
}
}
/**
* delete current user's cache file
*
*/
public function refresh(){
if($dir = opendir($this->dir)){
while (false !== ($file = readdir($dir))) {
if(!is_dir($file) && $file != '.' && $file != '..') {
if(strpos($file, 'u_')!==false){
@unlink($this->dir.$file);
}
}
}
}
}
}
CURL ??涓?涓?瓒?寮虹???戒護琛?宸ュ?鳳??跺???介??甯稿己澶э???Linux/Unix??????锛?涔???Windows??????锛???骞蟲?跺氨缁?甯稿??indows涓???嬌??url??涓?浜?娴?璇?锛???甯告?逛究锛????剁??url??娴?璇?姣??ㄦ?瑙??ㄥ??娴?璇?瑕?蹇?寰?澶?锛??逛究寰?澶???
1.curl?戒護甯??╅??椤? C:\>curl --help
Usage: curl [options...] <url>
Options: (H) means HTTP/HTTPS only, (F) means FTP only
?-a/--append??????? Append to target file when uploading (F)
?-A/--user-agent <string> User-Agent to send to server (H)
??? --anyauth?????? Tell curl to choose authentication method (H)
?-b/--cookie <name=string/file> Cookie string or file to read cookies from (H)
??? --basic???????? Enable HTTP Basic Authentication (H)
?-B/--use-ascii???? Use ASCII/text transfer
?-c/--cookie-jar <file> Write cookies to this file after operation (H)
?-C/--continue-at <offset> Resumed transfer offset
?-d/--data <data>?? HTTP POST data (H)
??? --data-ascii <data>?? HTTP POST ASCII data (H)
??? --data-binary <data>? HTTP POST binary data (H)
??? --negotiate???? Enable HTTP Negotiate Authentication (H)
??? --digest??????? Enable HTTP Digest Authentication (H)
??? --disable-eprt? Prevent curl from using EPRT or LPRT (F)
??? --disable-epsv? Prevent curl from using EPSV (F)
?-D/--dump-header <file> Write the headers to this file
??? --egd-file <file> EGD socket path for random data (SSL)
??? --tcp-nodelay?? Set the TCP_NODELAY option
?-e/--referer?????? Referer URL (H)
?-E/--cert <cert[:passwd]> Client certificate file and password (SSL)
??? --cert-type <type> Certificate file type (DER/PEM/ENG) (SSL)
??? --key <key>???? Private key file name (SSL)
??? --key-type <type> Private key file type (DER/PEM/ENG) (SSL)
??? --pass? <pass>? Pass phrase for the private key (SSL)
??? --engine <eng>? Crypto engine to use (SSL). "--engine list" for list
??? --cacert <file> CA certificate to verify peer against (SSL)
??? --capath <directory> CA directory (made using c_rehash) to verify
??????????????????? peer against (SSL)
??? --ciphers <list> SSL ciphers to use (SSL)
??? --compressed??? Request compressed response (using deflate or gzip)
??? --connect-timeout <seconds> Maximum time allowed for connection
??? --create-dirs?? Create necessary local directory hierarchy
??? --crlf????????? Convert LF to CRLF in upload
?-f/--fail????????? Fail silently (no output at all) on errors (H)
??? --ftp-create-dirs Create the remote dirs if not present (F)
??? --ftp-pasv????? Use PASV instead of PORT (F)
??? --ftp-ssl?????? Enable SSL/TLS for the ftp transfer (F)
?-F/--form <name=content> Specify HTTP multipart POST data (H)
??? --form-string <name=string> Specify HTTP multipart POST data (H)
?-g/--globoff?????? Disable URL sequences and ranges using {} and []
?-G/--get?????????? Send the -d data with a HTTP GET (H)
?-h/--help????????? This help text
?-H/--header <line> Custom header to pass to server (H)
?-i/--include?????? Include protocol headers in the output (H/F)
?-I/--head????????? Show document info only
?-j/--junk-session-cookies Ignore session cookies read from file (H)
??? --interface <interface> Specify network interface to use
??? --krb4 <level>? Enable krb4 with specified security level (F)
?-k/--insecure????? Allow curl to connect to SSL sites without certs (H)
?-K/--config??????? Specify which config file to read
?-l/--list-only???? List only names of an FTP directory (F)
??? --limit-rate <rate> Limit transfer speed to this rate
?-L/--location????? Follow Location: hints (H)
??? --location-trusted Follow Location: and send authentication even
??????????????????? to other hostnames (H)
?-m/--max-time <seconds> Maximum time allowed for the transfer
??? --max-redirs <num> Maximum number of redirects allowed (H)
??? --max-filesize <bytes> Maximum file size to download (H/F)
?-M/--manual??????? Display the full manual
?-n/--netrc???????? Must read .netrc for user name and password
??? --netrc-optional Use either .netrc or URL; overrides -n
??? --ntlm????????? Enable HTTP NTLM authentication (H)
?-N/--no-buffer???? Disable buffering of the output stream
?-o/--output <file> Write output to <file> instead of stdout
?-O/--remote-name?? Write output to a file named as the remote file
?-p/--proxytunnel?? Operate through a HTTP proxy tunnel (using CONNECT)
??? --proxy-anyauth? Let curl pick proxy authentication method (H)
??? --proxy-basic?? Enable Basic authentication on the proxy (H)
??? --proxy-digest? Enable Digest authentication on the proxy (H)
??? --proxy-ntlm??? Enable NTLM authentication on the proxy (H)
?-P/--ftp-port <address> Use PORT with address instead of PASV (F)
?-q???????????????? If used as the first parameter disables .curlrc
?-Q/--quote <cmd>?? Send command(s) to server before file transfer (F)
?-r/--range <range> Retrieve a byte range from a HTTP/1.1 or FTP server
??? --random-file <file> File for reading random data from (SSL)
?-R/--remote-time?? Set the remote file's time on the local output
??? --retry <num>?? Retry request <num> times if transient problems occur
??? --retry-delay <seconds> When retrying, wait this many seconds between each
??? --retry-max-time <seconds> Retry only within this period
?-s/--silent??????? Silent mode. Don't output anything
?-S/--show-error??? Show error. With -s, make curl show errors when they occur
??? --socks <host[:port]> Use SOCKS5 proxy on given host + port
??? --stderr <file> Where to redirect stderr. - means stdout
?-t/--telnet-option <OPT=val> Set telnet option
??? --trace <file>? Write a debug trace to the given file
??? --trace-ascii <file> Like --trace but without the hex output
?-T/--upload-file <file> Transfer <file> to remote site
??? --url <URL>???? Spet URL to work with
?-u/--user <user[:password]> Set server user and password
?-U/--proxy-user <user[:password]> Set proxy user and password
?-v/--verbose?????? Make the operation more talkative
?-V/--version?????? Show version number and quit
?-w/--write-out [format] What to output after completion
?-x/--proxy <host[:port]> Use HTTP proxy on given port
?-X/--request <command> Specify request command to use
?-y/--speed-time??? Time needed to trig speed-limit abort. Defaults to 30
?-Y/--speed-limit?? Stop transfer if below speed-limit for 'speed-time' secs
?-z/--time-cond <time> Transfer based on a time condition
?-0/--http1.0?????? Use HTTP 1.0 (H)
?-1/--tlsv1???????? Use TLSv1 (SSL)
?-2/--sslv2???????? Use SSLv2 (SSL)
?-3/--sslv3???????? Use SSLv3 (SSL)
??? --3p-quote????? like -Q for the source URL for 3rd party transfer (F)
??? --3p-url??????? source URL to activate 3rd party transfer (F)
??? --3p-user?????? user and password for source 3rd party transfer (F)
?-4/--ipv4????????? Resolve name to IPv4 address
?-6/--ipv6????????? Resolve name to IPv6 address
?-#/--progress-bar? Display transfer progress as a progress bar
2.?ユ?鵑〉?㈡?浠g??涓?????瀹???瀹? 渚?濡??ユ?句含涓?????棣?椤靛????js??浠g??
C:\>curl www.360buy.com | find "js"
? % Total??? % Received % Xferd? Average Speed?? Time??? Time???? Time? Current
???????????????????????????????? Dload? Upload?? Total?? Spent??? Left? Speed
?19? 158k?? 19 31744??? 0???? 0? 53531????? 0? 0:00:03 --:--:--? 0:00:03 65947<s
cript type="text/javascript" src="http://misc.360buyimg.com/201006/js/jquery-1.2
.6.pack.js"></script>
<script type="text/javascript" src="http://misc.360buyimg.com/201007/js/g.base.j
s"></script>
?76? 158k?? 76? 121k??? 0???? 0? 10763????? 0? 0:00:15? 0:00:11? 0:00:04? 7574<s
pan><a href="http://www.360buy.com/help/ziti/jiangsu.aspx#jssq" target="_blank" rel="external nofollow" target="_blank">
瀹胯?</a></span>
?99? 158k?? 99? 158k?? <span><a href="http://www.360buy.com/hel p/ziti/jiangsu.a
spx#jsnt" target="_blank" rel="external nofollow" target="_blank0">????</a></span>
100? 158k? 100? 158k??? 0???? 0? 12557????? 0? 0:00:12? 0:00:12 --:--:-- 18859
??????? <script type="text/javascript" src="http://misc.360buyimg.com/201007/js/
jd.lib.js"></script>
??????? <script type="text/javascript" src="http://misc.360buyimg.com/201007/js/
p.index.js"></script>
??????? <script type="text/javascript" src="http://wl.360buy.com/wl.js" ></scrip
t>
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.
js' type='text/javascript'%3E%3C/script%3E"));
2.????POST璇鋒?
a.浼???涓?涓??????跺??浠ヤ??ㄥ??寮??? C:\>curl -d action=get_basic_info http://localhost/1616.net/apps/contact/www/mobile.php
[{"contact_id":"3","last_update_time":"1285832338","md5":"7b682e0c3ed3b3bddb3219
a533477224"},{"contact_id":"2","last_update_time":"1286529929","md5":"49ac542f51
19512682b72f1d44e6fe81"},{"contact_id":"1","last_update_time":"1285830870","md5"
:"3926cb3b0320327c46430c6539d58e5e"}]
b.浼???澶?涓??????跺?椤葷?ㄥ??寮??鳳?????浼??ラ??
C:\>curl -d "action=edit&contact_id=2&name=testurl" http://localhost/1616.net/apps/contact/www/mobile.php
1
3.涓?杞芥??浠? 姣?濡?涓?杞界?懼害棣?椤電????瀹逛負baidu.html
C:\>curl -o baidu.html www.baidu.com
? % Total??? % Received % Xferd? Average Speed?? Time??? Time???? Time? Current
???????????????????????????????? Dload? Upload?? Total?? Spent??? Left? Speed
100? 6218? 100? 6218??? 0???? 0? 61564????? 0 --:--:-- --:--:-- --:--:--? 173k
4.灏?缃?绔?浜х????cookie??瀹瑰???ュ?版??浠朵腑
??url -c cookie.txt www.baidu.com
浜х??????浠?ookie.txt????瀹瑰?涓?锛?
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
.baidu.com?? ?TRUE?? ?/?? ?FALSE?? ?2147483647?? ?BAIDUID?? ?3EC2799E83C7187A26CBBA67CCB71822:FG=1
5.娴?璇?????缁?瀹?
杈??ュ?戒護
C:\>curl -H "Host:www.baidu.com" http://202.108.22.5/
ip?闆??202.108.22.5??ping????www.baidu.com浠ュ??杩?????ip?闆????
??杩????懼害棣?椤墊????????瀹?
濡?????渚胯??ヤ?涓?????www.abc.com锛???ip?闆??涓??瑰??锛???杩?????瀹規??绌虹??锛???涓哄????涓?ip?闆??涓??歸??浜?锛?杩??峰氨??浠ユ?璇?????缁?瀹??????g‘浜???
C:\>curl -H "Host:www.abc.com" http://202.108.22.5/
curl: (52) Empty reply from server
?ョ???村? http://www.blogkid.net/archives/2668.html
6.?ョ??缃?绔?澶翠俊??
C:\>curl -I www.baidu.com
HTTP/1.1 200 OK
Date: Fri, 08 Oct 2010 15:32:06 GMT
Server: BWS/1.0
Content-Length: 6218
Content-Type: text/html;charset=gb2312
Cache-Control: private
Expires: Fri, 08 Oct 2010 15:32:06 GMT
Set-Cookie: BAIDUID=6E8167DF4E04A22A0659BBA1BE2905E7:FG=1; expires=Fri, 08-Oct-4
0 15:32:06 GMT; path=/; domain=.baidu.com
P3P: CP=" OTI DSP COR IVA OUR IND COM "
Connection: Keep-Alive
7.?ョ??URL璺寵漿
C:\>curl -L -I www.google.com
HTTP/1.1 302 Found
Location: http://www.google.com.hk/url?sa=p&hl=zh-CN&cki=PREF%3DID%3Dd0fa5e644a9
f891c:FF%3D2:LD%3Dzh-CN:NW%3D1:TM%3D1286551973:LM%3D1286551973:S%3DPQB5WhVsd17Bq
38k&q=http://www.google.com.hk/&ust=1286552003174649&usg=AFQjCNEwGJlI-YF0TG-6BiW
ILw7U2qsr5Q
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Set-Cookie: PREF=ID=d0fa5e644a9f891c:NW=1:TM=1286551973:LM=1286551973:S=oAe_1PXO
MrFd73Jy; expires=Sun, 07-Oct-2012 15:32:53 GMT; path=/; domain=.google.com
Set-Cookie: NID=39=C_aIB4kMtsJnMR5kwJKF9XAhB9_sEKTp5Qe-Y6Zcu7nNVrrBmKrr-687Zhf_r
-wVNniv4kbb8BRCBR52EN2HdxaL2lGCBxUlEWjkGdZctAqdjyzZbwTb2Hh05UgYMTIO; expires=Sat
, 09-Apr-2011 15:32:53 GMT; path=/; domain=.google.com; HttpOnly
Date: Fri, 08 Oct 2010 15:32:53 GMT
Server: gws
Content-Length: 458
X-XSS-Protection: 1; mode=block
HTTP/1.1 302 Found
Location: http://www.google.com.hk/
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Set-Cookie: PREF=ID=d0fa5e644a9f891c:FF=2:LD=zh-CN:NW=1:TM=1286551973:LM=1286551
973:S=PQB5WhVsd17Bq38k; expires=Sun, 07-Oct-2012 15:32:53 GMT; path=/; domain=.g
oogle.com.hk
Date: Fri, 08 Oct 2010 15:32:53 GMT
Server: gws
Content-Length: 222
X-XSS-Protection: 1; mode=block
HTTP/1.1 200 OK
Date: Fri, 08 Oct 2010 15:32:53 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=Big5
Set-Cookie: PREF=ID=3f9f2340941ea76f:NW=1:TM=1286551973:LM=1286551973:S=m9wrFWJe
Jbk4aFK2; expires=Sun, 07-Oct-2012 15:32:53 GMT; path=/; domain=.google.com.hk
Set-Cookie: NID=39=Mlebw-qjMEK1ABTu-W1YWoQ-Tk27--cOtwLLrDWhmU8y0fqwgeyNz06XBZsYG
9yNwSCO_Ryzzt7q1GUXHgrM2jijr9vmLsW9ZXT2k6pve8f-IrdMyLJok4lRImiskdLR; expires=Sat
, 09-Apr-2011 15:32:53 GMT; path=/; domain=.google.com.hk; HttpOnly
Server: gws
X-XSS-Protection: 1; mode=block
Transfer-Encoding: chunked
curl: (18) transfer closed with outstanding read data remaining
寤朵幾??璇夥?
http://blog.chinaunix.net/u/5591/showart.php?id=1957520
http://www.blogkid.net/archives/2668.html
http://www.baidu.com/s?wd=curl
http://www.google.com/search?hl=en&source=hp&q=curl
http://blog.s135.com/post/389/
==============================================
琛ュ???ヨ??锛?
??浠ョ??浣??戒護琛?娴?瑙???
1??寮???gzip璇鋒?
curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte
2?????х?椤電????搴??堕?? curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" "http://www.kklinux.com"
3. ???х???瑰???ㄦ?? curl -o /dev/null -s -w %{http_code} "http://www.kklinux.com"
4??浠?ttp1.0??璁?璇鋒?锛?榛?璁や負http1.1锛??
curl -0 ..............?
??????1锛?璇誨??缃?椤德?
????$ curl linuxidc.com">http://www.linuxidc.com?
????2锛?淇?瀛?缃?椤德?
????$ curl http://www.linuxidc.com > page.html $ curl -o page.html http://www.linuxidc.com?
????3锛?浣跨?ㄧ??proxy???″?ㄥ???剁???o?-x?
????$ curl -x 123.45.67.89锛?1080 -o page.html http://www.linuxidc.com?
????4锛?浣跨??ookie?ヨ?闆?session淇℃???
????$ curl -x 123.45.67.89锛?1080 -o page.html -D cookie0001.txt http://www.linuxidc.com?
option锛? -D ????http??response???㈢??cookie淇℃??瀛??頒?涓??瑰??????浠朵腑?夥?杩??鳳?褰?椤甸?㈣?瀛???age.html?????訛?cookie淇℃??涔?琚?瀛??頒?cookie0001.txt??????
????5锛??d?锛?涓?涓?娆¤?塊?????跺??锛?濡?浣?缁х畫浣跨?ㄤ?娆$??涓???cookie淇℃??????
????浣跨??ption?ユ??涓?娆$??cookie淇℃??杩藉????ttp request???㈠?夥?-b?
????$ curl -x 123.45.67.89锛?1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com?
6锛?娴?瑙??ㄤ俊??~~~~?
??????瀹???宸辮?娆¤?塊????瀹gО????宸辯??娴?瑙??ㄤ俊??锛? -A
curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.yahoo.com?
杩??鳳????″?ㄧ???ュ?拌?塊????瑕?姹?锛?浼?璁や負浣???涓?涓?杩?琛???indows 2000涓???IE6.0锛??垮?垮?匡??跺??涔?璁鎬??ㄧ?????規???哄????
??"Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686"????浠ュ??璇?瀵規?逛???涓???C涓?璺?????Linux锛??ㄧ????Netscape 4.73锛??靛?靛?德?
7锛?
???涓?涓????″?ㄧ??甯哥?ㄧ?????舵?規?锛?灏辨??妫???ttp璁塊????referer??姣?濡?浣???璁塊??棣?椤碉???璁塊?????㈡????瀹???涓?杞介〉锛?杩?绗?浜?娆¤?塊????referer?闆??灏辨??绗?涓?娆¤?塊??????????椤甸?㈠?奧?
????杩??鳳????″?ㄧ????瑕????闆?逛?杞介〉?㈡??娆¤?塊????referer?闆??涓? ??棣?椤電???闆??锛?灏卞??浠ユ??瀹??f??涓???杩?浜?~~~~~?
璁ㄥ??璁ㄥ??~~~??灏辨??瑕???杩?~~~~~锛?锛?
骞稿ソcurl缁???浠???渚?浜?璁懼??referer??option锛? -e
curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.yahoo.com" -o page.html -D cookie0001.txt http://www.yahoo.com?
杩??鳳?灏卞??浠ラ??瀵規?圭?????″???浣???浠?mail.yahoo.com?瑰?繪??涓??炬?ヨ??ョ??浜?锛??靛?靛?德?
8锛?curl 涓?杞芥??浠堵?
????璁茶?浜?锛?涓?杞介〉?㈠?頒?涓???浠堕??锛???浠ヤ嬌??-o 锛?涓?杞芥??浠朵???涓??楓??
姣?濡?锛??curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
杩?????澶у?朵?涓??扮??option锛? -O
澶у????O锛?杩?涔?????curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
杩??鳳?灏卞??浠ユ???ф???″?ㄤ?????浠跺??锛????ㄥ???ㄦ???頒?锛??
???ヤ?涓??村ソ?ㄧ????
濡???screen1.JPG浠ュ?杩???screen2.JPG??screen3.JPG??....??screen10.JPG??瑕?涓?杞斤??句???杩?瑕?璁╂??浠???涓?涓?script?ュ????杩?浜???浣?锛?
涓?骞詫?
??url?????杩?涔???灏卞??浠ヤ?锛?
curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG?
?靛?靛?碉???瀹沖?э?锛?~~~?
9锛?
???ワ???浠?缁х畫璁茶В涓?杞斤?
curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG?
杩??蜂駭????涓?杞斤?灏辨??
~zzh/001.JPG
~zzh/002.JPG
...
~zzh/201.JPG
~nick/001.JPG
~nick/002.JPG
...
~nick/201.JPG?
澶??逛究??浜??э????????
???楂??村?澶??╀???
?變?zzh/nick涓?????浠跺???芥??001锛?002...锛?201锛?涓?杞戒??ョ????浠堕????锛????㈢???????㈢????浠堕?界?瑕?????浜?~~~?
娌″?崇郴锛???浠?杩????寸????锛?
curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG?
--杩???.....??瀹?涔???浠跺????涓?杞斤?
--瀵瑰ご锛??靛?碉??
#1??????锛???????{zzh,nick}杩??ㄥ??锛?绗?涓?娆″????zh锛?绗?浜?娆″????ick
#2浠h〃??????锛?????绗?浜?娈靛?????ㄥ??---[001-201]锛????間?001??涓?????01
杩??鳳???瀹?涔??烘?ヤ?杞戒??ョ????浠跺??锛?灏卞????浜?杩??鳳?
???ワ? ~zzh/001.JPG ---> 涓?杞藉??锛? 001-zzh.JPG
???ワ? ~nick/001.JPG ---> 涓?杞藉??锛? 001-nick.JPG?
杩??蜂??ワ?灏變?????浠堕????????靛?德?
9锛?
缁х畫璁蹭?杞? ??浠?骞蟲?跺??indows骞沖?頒?锛?flashget杩??風??宸ュ?峰??浠ュ府??浠?????骞惰?涓?杞斤?杩???浠ユ??绾跨畫浼???
curl?ㄨ?浜??歸???涓?杈?缁?璋?锛??垮?柯?
姣?濡???浠?涓?杞?creen1.JPG涓?锛?绐??舵??绾誇?锛???浠?灏卞??浠ヨ??峰?濮?缁?浼?
curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG?
褰??訛?浣?涓?瑕??誇釜flashget涓?杞戒?涓???????浠舵?ョ?寮???~~~~????涓?杞借蔣浠剁????????浠跺??涓?涓?瀹??界?ㄥ??~~?
????涓?杞斤???浠?浣跨?ㄨ?涓?option灏卞??浠ヤ?锛? -r
涓句?璇存??
姣?濡???浠???涓?涓?http://cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 瑕?涓?杞斤?璧佃??甯????佃????璇?:D 锛?
??浠?灏卞??浠ョ?ㄨ??風???戒護锛?
curl -r 0-10240 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
curl -r 10241-20480 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
curl -r 20481-40960 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
curl -r 40961- -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3?
杩??峰氨??浠ュ????涓?杞藉????
涓?杩?浣???瑕???宸辨??杩?浜??寸?????浠跺??骞惰搗?? 濡???浣???NIX???規??锛???cat zhao.part* > zhao.mp3灏卞??浠? 濡????ㄧ????Windows锛???opy /b ?ヨВ?沖?э??靛?德?
涓??㈣?茬???芥??http??璁???涓?杞斤??跺??ftp涔?涓??峰??浠ョ?ㄣ??
?ㄦ???锛?
curl -u name:passwd ftp://ip:port/path/file
????澶у?剁??????
curl ftp://name:[email?protected]:port/path/file?
??
10)涓?浼???option?? -T?
姣?濡???浠???ftp浼?涓?涓???浠訛??curl -T localfile -u name:passwd ftp://upload_site:port/path/?
褰??訛???http???″?ㄤ?浼???浠朵???浠? 姣?濡??curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi
娉ㄦ??锛?杩??跺??锛?浣跨?ㄧ????璁???HTTP??PUT method?
????璇村??UT锛??垮?匡????惰?╄?????寵搗?ヤ??朵???绉?methos杩?娌¤?插???
GET??POST?戒??藉??????
http??浜や?涓?琛ㄥ??锛?姣?杈?甯哥?ㄧ????POST妯″???GET妯″??
GET妯″?浠?涔?option?戒????????瑕???????????rl???㈠氨??浠ヤ?
姣?濡?锛?
curl http://www.yahoo.com/login.cgi?user=nickwolfe&password=12345?
??POST妯″???option???? -d?
姣?濡?锛?curl -d "user=nickwolfe&password=12345" http://www.yahoo.com/login.cgi
灏辯?稿?浜???杩?涓?绔??瑰???轟?娆$?婚???寵??~~~~?
?闆?璇ョ??ET妯″?杩???POST妯″?锛?瑕???瀵歸?㈡???″?ㄧ??绋?搴?璁懼?????
涓??歸??瑕?娉ㄦ??????锛?POST妯″?涓?????浠朵?????浠朵?浼?锛?姣?濡?
<form method="POST" enctype="multipar/form-data" action="http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi">
<input type=file name=upload>
<input type=submit name=nick value="go">
</form>
杩??蜂?涓?HTTP琛ㄥ??锛???浠?瑕???url杩?琛?妯℃??锛?灏辮?ユ??杩??風??璇?娉?锛?
curl -F [email?protected] -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi?
缃?缃??????蹭?杩?涔?澶?锛??跺??curl杩???寰?澶?寰?澶???宸у???ㄦ?
姣?濡? https???跺??浣跨?ㄦ???拌??涔??灏卞??浠ヨ??? curl -E localcert.pem https://remote_server?
??姣?濡?锛?浣?杩???浠ョ??url??杩?dict??璁??繪?ュ????~~~~
curl dict://dict.org/d:computer?
浠?澶╀負浜?妫??ユ?????虹??涓繪?轟???????????????澶?妗?锛??ㄤ嬌??get涓??界?????典?锛??懼?頒?curl杩?涓??戒護琛?娴????ㄥ?戒護锛????闆?跺??ost??璋??ㄨ?????濂界??锛??瑰?????╀?瀵規??浜や俊???????
?村???拌?琛?杈?楠?锛?瀵逛????沖?????涓???????iibeian.gov.cn杩?琛?楠?璇???????澶?妗?淇℃????甯告????????拌?绡???绔?寰?涓???锛??逛負杞?璐達??
????????锛?
curl -d "cxfs=1&ym=xieyy.cn" http://www.miibeian.gov.cn/baxx_cx_servlet?
?ㄥ?烘?ョ??淇℃??涓?杩?琛?杩?婊わ?????澶?妗??蜂俊??锛?骞惰?劇疆涓?涓???璇?浣?锛?灏?????锛?澶?妗??峰????璇?浣??ュ??
??url?戒護锛?post??浜ゅ甫绌烘?肩???版???
浠?澶╁?剁?堕???頒?涓????碉????崇??url?誨?ヤ?涓?缃?椤碉??????村???拌?post???版????甯?┖?箋??姣?濡??ㄦ?峰??涓?abcdef"锛?瀵???涓?abc def"锛??朵腑??涓?涓?绌烘?鹼????ф??浠ュ?????瑰???浜わ??
curl -D cookie -d "username=abcdef&password=abc def" http://login.xxx.com/??绀虹?誨?ュけ璐ャ???
浜????ョ??curl????man curl???懼?幫??
d/--data (HTTP) Sends the speci?ed data in a POST request to the HTTP server, in a way that can emulate as if a user has ?lled in a HTML form and pressed the?
submit button. Note that the data is sent exactly as speci?ed with no extra processing (with all newlines cut off). The data is expected to be "url-encoded".?
This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F/--form. If this option is used?
more than once on the same command line, the data pieces speci?ed will be merged together with a separating &-letter. Thus, using ??-d name=daniel -d?
skill=lousy?? would generate a post chunk that looks like ??name=daniel&skill=lousy??.?
浜????圭????
curl -D cookie -d "username=abcdef" -d "password=abc efg" http://login.xxx.com/杩??峰氨?芥?????誨?ヤ????
(璐d換缂?杈?锛?椋?椋???澶?) ?
Curl??Linux涓?涓?涓?寰?寮哄ぇ??http?戒護琛?宸ュ?鳳??跺???藉????寮哄ぇ??
1) 浜?璇?涓?璇達???浠?杩???寮?濮??э?
$ curl http://www.linuxidc.com
??杞????锛?www.linuxidc.com ??html灏辯????????版?劇ず?ㄥ?骞?涓?浜?????~
2) ??锛?瑕??蟲??璇昏??ラ〉?㈠??涓??ワ???涓???瑕?杩??峰???
$ curl http://www.linuxidc.com > page.html
褰??跺??浠ワ?浣?涓??ㄨ?涔?楹葷????锛?
??url????缃?option灏卞ソ锛?瀛?涓?http??缁???锛??ㄨ?涓?option: -o
$ curl -o page.html http://www.linuxidc.com
杩??鳳?浣?灏卞??浠ョ???闆?骞?涓??虹?頒?涓?涓?杞介〉?㈣?搴???绀恒??绛?杩?灞???00%锛????跺氨 OK??
3) 浠?涔?浠?涔?锛?锛?璁塊??涓??幫???瀹???浣???proxy娌℃??璁懼??浜???
浣跨??url???跺??锛??ㄨ?涓?option??浠ユ??瀹?http璁塊????浣跨?ㄧ??proxy???″?ㄥ???剁???o? -x
$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com
4) 璁塊????浜?缃?绔????跺??姣?杈?璁ㄥ??锛?浠?浣跨??ookie?ヨ?闆?session淇℃????
??IE/NN杩??風??娴?瑙????褰??跺??浠ヨ交??澶???cookie淇℃??锛?浣???浠???curl???.....
??浠??ュ???杩?涓?option: -D <?? 杩?涓?????http??response???㈢??cookie淇℃??瀛??頒?涓??瑰??????浠朵腑??
$ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com
杩??鳳?褰?椤甸?㈣?瀛???age.html?????訛?cookie淇℃??涔?琚?瀛??頒?cookie0001.txt?????
5锛??d?锛?涓?涓?娆¤?塊?????跺??锛?濡?浣?缁х畫浣跨?ㄤ?娆$??涓???cookie淇℃?????瑕??ラ??锛?寰?澶?缃?绔??芥??????瑙?浣???cookie淇℃??锛??ュ?ゆ??浣???涓???涓???瑙??╄?塊??浠?浠???缃?绔?????
杩?娆℃??浠?浣跨?ㄨ?涓?option?ユ??涓?娆$??cookie淇℃??杩藉????ttp request???㈠?夥? -b
$ curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com
杩??鳳???浠?灏卞??浠ュ??涔?妯℃????????IE??浣?锛??昏?塊??缃?椤典?锛?
6锛?绋?寰?绛?绛?????~??濂藉??蹇?璁頒?涔?浜?????~
瀵逛?锛???娴?瑙??ㄤ俊??
??浜?璁ㄥ????缃?绔??昏???浠?浣跨?ㄦ??浜??瑰????娴?瑙??ㄥ?昏?塊??浠?浠?锛????跺???磋???????锛?杩?瑕?浣跨?ㄦ??浜??瑰????????????NND锛????????堕?翠負浜?瀹??繪?捐?浜???寮???娴?瑙??ㄥ???锛?
濂藉??url缁???浠???渚?浜?涓?涓????ㄧ??option锛???浠ヨ?╂??浠???????瀹???宸辮?娆¤?塊????瀹gО????宸辯??娴?瑙??ㄤ俊??锛? -A
$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com
杩??鳳????″?ㄧ???ュ?拌?塊????瑕?姹?锛?浼?璁や負浣???涓?涓?杩?琛???indows 2000涓??? IE6.0锛??垮?垮?匡??跺??涔?璁鎬??ㄧ?????規???哄???
??"Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686"????浠ュ??璇?瀵規?逛???涓???PC涓?璺?????Linux锛??ㄧ????Netscape 4.73锛??靛?靛??
7锛????涓?涓????″?ㄧ??甯哥?ㄧ?????舵?規?锛?灏辨??妫???ttp璁塊????referer??姣?濡?浣???璁塊??棣?椤碉???璁塊?????㈡????瀹???涓?杞介〉锛?杩?绗?浜?娆¤?塊???? referer?闆??灏辨??绗?涓?娆¤?塊??????????椤甸?㈠?闆????杩??鳳????″?ㄧ????瑕????闆?逛?杞介〉?㈡??娆¤?塊????referer?闆??涓???棣?椤電???闆??锛?灏卞??浠ユ??瀹??f??涓??? 杩?浜?????~
璁ㄥ??璁ㄥ?? ~??灏辨??瑕???杩?????~锛?锛?
骞稿ソcurl缁???浠???渚?浜?璁懼??referer??option锛? -e
$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.linuxidc.com" -o page.html -D cookie0001.txt http://www.linuxidc.com
杩??鳳?灏卞??浠ラ??瀵規?圭?????″???浣???浠?mail.linuxidc.com?瑰?繪??涓??炬?ヨ??ョ??浜?锛??靛?靛??
8锛????????????版???浠?涔???瑕???涓?瑗誇?锛?????- ?╃??url 涓?杞芥??浠?
????璁茶?浜?锛?涓?杞介〉?㈠?頒?涓???浠堕??锛???浠ヤ嬌??-o 锛?涓?杞芥??浠朵???涓??楓??姣?濡?锛?
$ curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
杩?????澶у?朵?涓??扮??option锛? -O 澶у????O锛?杩?涔????
$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
杩??鳳?灏卞??浠ユ???ф???″?ㄤ?????浠跺??锛????ㄥ???ㄦ???頒?锛?
???ヤ?涓??村ソ?ㄧ????
濡???screen1.JPG浠ュ?杩???screen2.JPG??screen3.JPG??....??screen10.JPG??瑕?涓?杞斤??句???杩?瑕?璁╂??浠???涓?涓?script?ュ????杩?浜???浣?锛?
涓?骞詫?
??url?????杩?涔???灏卞??浠ヤ?锛?
$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG
?靛?靛?碉???瀹沖?э?锛? ~
9锛????ワ???浠?缁х畫璁茶В涓?杞斤?
$ curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG
杩??蜂駭????涓?杞斤?灏辨??
~zzh/001.JPG
~zzh/002.JPG
...
~zzh/201.JPG
~nick/001.JPG
~nick/002.JPG
...
~nick/201.JPG
澶??逛究??浜??э???????
???楂??村?澶??╀???
?變?zzh/nick涓?????浠跺???芥??001锛?002...锛?201锛?涓?杞戒??ョ????浠堕????锛????㈢???????㈢????浠堕?界?瑕?????浜? ~
娌″?崇郴锛???浠?杩????寸????锛?
$ curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG
??杩???.....??瀹?涔???浠跺????涓?杞斤? ??瀵瑰ご锛??靛?碉?
杩??鳳???瀹?涔??烘?ヤ?杞戒??ョ????浠跺??锛?灏卞????浜?杩??鳳????ワ? ~zzh/001.JPG ??-> 涓?杞藉??锛? 001-zzh.JPG ???ワ? ~nick/001.JPG ??-> 涓?杞藉??锛? 001-nick.JPG
杩??蜂??ワ?灏變?????浠堕????????靛??
========================
function vpost($url, $data) { // 妯℃????浜ゆ?版???芥?? $curl = curl_init(); // ???ㄤ?涓?CURL浼?璇?
curl_setopt($curl, CURLOPT_URL, $url); // 瑕?璁塊?????闆??
//curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 瀵矽?よ??璇?涔??ユ???妫??? //curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 浠?璇?涔?腑妫???SL??瀵?绠?娉????????? //curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 妯℃???ㄦ?蜂嬌?ㄧ??娴?瑙??? //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 浣跨?ㄨ???ㄨ煩杞?
//curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // ???ㄨ?劇疆Referer
curl_setopt($curl, CURLOPT_POST, 1); // ????涓?涓?甯歌???Post璇鋒?
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post??浜ょ???版????
//curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // 璇誨??涓??㈡???ㄥ????Cookie淇℃??
//curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 璁劇疆瓒??堕???堕?叉?㈡?誨驚??
//curl_setopt($curl, CURLOPT_HEADER, 0); // ?劇ず杩?????Header?哄????瀹? //curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // ?峰????淇℃??浠ユ??浠舵???褰㈠?杩???
$tmpInfo = curl_exec($curl); // ?ц???浣?
if (curl_errno($curl)) {
echo 'Errno' . curl_error($curl);
}
curl_close($curl); // ?抽??CURL浼?璇?
return $tmpInfo; // 杩????版??
}
//method=%E6%9F%A5%E8%AF%A2&jc=%E7%B2%A4&hphm=ahx843&hpzl=02&lxdh=8681&randcode2=9898
$url = "http://[email?protected]@@@@[email?protected]@@@@[email?protected]@@@@cn/cx/wzss/wzss.do";
$fields_string = array (
"method" => "%E6%9F%A5%E8%AF%A2",
"jc" => "%E7%B2%A4",
"hphm" => "ahx843",
"hpzl"=>"02",
"lxdh"=>"8681",
"randcode2"=>"9898"
);//搴?璇ユ?逛負"name=zhangsan&action=234234&age=20"
echo $table = vpost($url, $fields_string);