茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1670505 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_2283101.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

小企鵝開談 : [轉貼]curl 指令用法

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]curl 指令用法

curl 指令用法

轉錄整理自: Linux curl使用简单介绍

curl 是 Linux 下一個很強大的 http 命令列工具
1) 取得網頁內容,螢幕輸出
$ curl http://www.linuxidc.com

2) -o: 取得網頁內容,檔案輸出
$ curl -o page.html http://www.linuxidc.com

3) -x: 指定 http 使用的 proxy
$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com

4) -D: 把 http response 裡面的 cookie 資訊另存新檔
$ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

5)-b: 把 cookie 資訊加到 http request 裡
$ curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com

6)-A: 設定瀏覽器資訊
#Windows 2000上的 IE6.0
$ 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
# Linux Netscape 4.73
$ curl -A "Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

7)-e: 設定 referrer
另外一個伺服器端常用的限制方法,就是檢查 http 訪問的 referer。比如你先訪問首頁,再訪問裡面所指定的下載頁,這第二次訪問的 referer 位址就是第一次訪問成功後的頁面位址。這樣,伺服器端只要發現對下載頁面某次訪問的 referer 位址不是首頁的位址,就可以斷定那是個盜連了
$ 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

8)-O: 使用伺服器上的檔案名,存在本地
$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG

9)可使用 Regular Expression 抓取所有 match 的檔案,指定 match 的群組內容為新檔名
$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG
$ 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

10)-c: 續傳 (只能用在原本是 curl 傳輸的檔案)
$ curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG

11) -r: 分塊下載
$ 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
Linux用 cat zhao.part* > zhao.mp3合併
Windows用copy /b 合併

12) -u: 指定 FTP 帳號密碼

$ curl -u name:passwd ftp://ip:port/path/file
$ curl ftp://name:passwd@ip:port/path/file

13) -T: 上傳檔案
$ curl -T localfile -u name:passwd ftp://upload_site:port/path/
$ curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi
(注意這時候使用的協定是 HTTP 的 PUT method)

14) Http GET 與 POST 模式
GET 模式什麼 option 都不用,只需要把變數寫在 url 裡面就可以了比如:
$ curl http://www.linuxidc.com/login.cgi?user=nickwolfe&password=12345
而 POST 模式的 option 則是 -d
$ curl -d "user=nickwolfe&password=12345" http://www.linuxidc.com/login.cgi
到底該用 GET 模式還是 POST 模式,要看對面伺服器的程式設定。比如 POST 模式下的文件上傳
<form action="http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi" enctype="multipar/form-data" method="POST">
<input name="upload" type="file"/>
<input name="nick" type="submit" value="go"/></form>

這樣一個 HTTP 表單,我們要用 curl 進行模擬,就該是這樣的語法:
$ curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi

15) https 使用本地認證
$ curl -E localcert.pem https://remote_server

16) 通過 dict 協定去查字典
$ curl dict://dict.org/d:computer

原文出處:Evelyn's Note: curl 指令用法
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]cURL 指令用法與教學

cURL 指令用法與教學

cURL 和 wget 一樣是 linux 中檔案下載時非常實用的工具,
對於大部份的下載工作兩者都同樣能達成,
curl 比 wget 強大的地方在於他還能支援上傳,
然而 curl 可以應用的地方和方式太多了無法一一深入介紹,
所以我先在最下面列出 curl 指令的說明。


之後若有實際應用 curl 的例子或遇上的問題,
會再以另外的文章補充在這裡:

  1. curl: (3) [globbing] illegal character in range specification at pos …
  2. cURL 批次下載指令教學
如果在這邊沒看到如何解決你遇上的問題,
也可以參考我的另一篇  wget 指令用法與教學
因為說不定是同樣的問題,只是我用 wget 解決掉了 XD

curl 指令用法如下:
Curl Manual


關鍵字:curl, post, curl linux, curl command, 教學
參考資料:

原文出處: cURL 指令用法與教學 @ 符碼記憶
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]cURL 批次下載指令教學

cURL 批次下載指令教學

在先前的文章中有提到,
cURL 和 wget 一樣是 linux 中檔案下載時非常實用的工具,
大部份的下載工作兩者都同樣能達成,
不同的是 curl 還可以支援上傳的功能。
想知道兩者的用法可以先到我先前整理的文章看一下:
  1. wget 指令用法與教學
  2. cURL 指令用法與教學

這篇要來說的是 curl 如何支援批次下載,
原本想說大部份的下載功能 curl 和 wget 都一樣,
沒想到用 wget 要批次下載時卻出現了這樣的警告。
「Warning: wildcards not supported in HTTP.」
「警告: HTTP 不支援萬用字元。」

原因很明顯啦,就是 wget 的 HTTP 不支援萬用字元的批次下載。
幸好換到 curl 這個問題簡直就是 a piece of cake。
只要善用 [ ] 即可,請看以下範例:


下載單一檔案:
# curl -O http://xxx.xx/filename.xxx
批次下載編號 1,2~15:
# curl -O http://xxx.xx/filename[1-15].xxx
批次下載編號 01,02~15,自動補0:
# curl -O http://xxx.xx/filename[01-15].xxx

這次我用來解決問題的指令和結果如下:

# curl -O http://vault.centos.org/5.7/isos/x86_64/CentOS-5.7-x86_64-bin-[1-8]of8.iso
[1/8]: http://vault.centos.org/5.7/isos/x86_64/CentOS-5.7-x86_64-bin-1of8.iso --> CentOS-5.7-x86_64-bin-1of8.iso
--_curl_--http://vault.centos.org/5.7/isos/x86_64/CentOS-5.7-x86_64-bin-1of8.iso
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 627M 100 627M 0 0 141k 0 1:15:26 1:15:26 --:--:-- 205k
[2/8]: http://vault.centos.org/5.7/isos/x86_64/CentOS-5.7-x86_64-bin-2of8.iso --> CentOS-5.7-x86_64-bin-2of8.iso
--_curl_--http://vault.centos.org/5.7/isos/x86_64/CentOS-5.7-x86_64-bin-2of8.iso
100 632M 100 632M 0 0 101k 0 1:46:27 1:46:27 --:--:-- 81717
[3/8]: http://vault.centos.org/5.7/isos/x86_64/CentOS-5.7-x86_64-bin-3of8.iso --> CentOS-5.7-x86_64-bin-3of8.iso
--_curl_--http://vault.centos.org/5.7/isos/x86_64/CentOS-5.7-x86_64-bin-3of8.iso
100 632M 100 632M 0 0 84003 0 2:11:40 2:11:40 --:--:-- 82888
......

以上就是用 curl 批次下載檔案的方法啦,供大家參考。
值得一提的是雖然 
[ ] 非常好用,但偶爾 curl 也會會錯意,
如果檔名中有   [ ] ,curl 可是會誤會你的意思而發生錯誤的喔!
請參考: curl: (3) [globbing] illegal character in range specification at pos …

如果還想知道我用了 curl 做了什麼其他的事,或遇上了什麼問題,
我都已經統一整理在  cURL 指令用法與教學 囉!歡迎大家參考指教 :p

關鍵字:cURL, 批次, 下載, 萬用字元, 指令, 教學
參考資料:

原文出處: cURL 批次下載指令教學 @ 符碼記憶
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]cURL errors

curl: (3) [globbing] illegal character in range specification at pos …

最近在使用 curl 時出現了這個問題,
後來查了資料發現是檔名中出現了 [ ] ,
curl 會將 [ ] 用於批次下載 (globbing) 而非直接用在檔名,
所以當 curl 試圖將 [ ] 中的內容解讀時就會發生錯誤。

圖片來源:http://curl.haxx.se/

解決方法有兩種:
  1. 將檔名出現   [ ] 的地方改用   \[ \] 。
  2. 使用 curl 的參數  
    --globoff,告訴 curl 你是要指定檔名而非批次下載。
雖然  [ ] 在這邊讓我們發生了錯誤很討厭,
但他在 curl 中還是有大大的功能喔!請參考: cURL 批次下載指令教學
更多關於 curl 和另一個 linux 下載工具 wget 的介紹,請參考:
  1. wget 指令用法與教學
  2. cURL 指令用法與教學
關鍵字:curl: (3) [globbing] illegal character in range specification at pos
參考資料:


原文出處: curl: (3) [globbing] illegal character in range specification at pos … @ 符碼記憶

curl: (56) Failure when receiving data from the peer

前一陣子使用了 curl 來完成一些工作,
也寫了幾篇介紹性的文章說明 curl 的用法,文章整理如下:
  1. cURL 指令用法與教學
  2. curl: (3) [globbing] illegal character in range specification at pos …

  3. cURL 批次下載指令教學

今天要介紹的則是我在使用 curl 時遇上的一個錯誤:
「curl: (56) Failure when receiving data from the peer」
關於這個錯誤網路上眾說紛紜,不過似乎沒有明確的解決方式。
有的人是更新到最新版後就解決了,不過對我似乎沒用。

後來發現似乎是我用 curl 上載的 server 有點問題,
正常來說server收到 http put 的request 後應該要回傳 100 continue,
指示 client 可以把要上傳的資料傳上來, 然而該 server 卻直接回傳 200 OK,

curl 判斷我們在 200 OK後又繼續上傳資料,所以會產生這個錯誤訊息,
不過東西還是都可以正常傳上去就是了。

說了這麼多其實還是沒有明確的解法,
只是讓大家知道出現這個錯誤時可能也是和我一樣的原因。
也許遇到的時候可以檢查一下 server 回傳的 http 訊息喔!
另外似乎在連線有變動後又送資料或request,好像也會出現這個訊息~

關鍵字:curl: (56) Failure when receiving data from the peer, 錯誤訊息, 原因, 解決
參考資料:

原文出處: curl: (56) Failure when receiving data from the peer @ 符碼記憶
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]How to pass a variable in a curl command in shell scripting
How to pass a variable in a curl command in shell scripting

I have a curl command:
curl -u ${USER_ID}:${PASSWORD} -X GET 'http://lppma670.gso.aexp.com:8080/rest/job-execution/job-details/${job_id}'

The variable job_id has a value in it, say, 1160. When I execute the curl command in shell it gives me the following error:
{"message":"Sorry. An unexpected error occured.", "stacktrace":"Bad Request. The request could not be understood by the server due to malformed syntax."}

If I pass the number '1160' directly in the command, as shown below, the curl command works.
curl -u ${USER_ID}:${PASSWORD} -X GET 'http://lppma670.gso.aexp.com:8080/rest/job-execution/job-details/1160'

Can someone please help me out? I wanna be able to pass the value of the variable in the curl command.



When using variables in shell, you can only use doubles quotes, not single quotes : the variables inside single quotes are not expanded. Learn the difference between ' and " and `. See http://mywiki.wooledge.org/Quotes and http://wiki.bash-hackers.org/syntax/words

Double quotes while assigning the value 1160 to job_id? You mean like this? "job_id=1160". And then call it inside the curl command using ${job_id}?

yes : job_id=1160;
curl -u ${USER_ID}:${PASSWORD} -X GET "http://lppma670.gso.aexp.com:8080/rest/job-execution/job-de‌​tails/${job_id}"



原文出處:bash - How to pass a variable in a curl command in shell scripting - Stack Overflow
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|