code style

12/28/2008

流星之絆

連著幾天把剛放送結束的流星之絆 看完

東野圭吾(推理小說家) 加上 宮藤官九郎(鬼才編劇)

又搞笑又沈重又歡樂又哀傷的日劇

而且戶田惠梨香有演出!正妹 最高!!

From UtOpIaN


12/07/2008

wget & curl

因為工作上需要, 想要自動化上傳/下載檔案到web server上

所以就survey了wget與curl 這裡有兩者的比較 wget vs curl

不過在https上遇到了一些問題 因為以前沒有研究過這方面的東西

總之wget/curl要連線到https/ssl的server上必須要有ca憑證 cacert.pem
wget --ca-certificate=cacert.pem url
curl --cacert cacert.pem url

接下來就是自動login的方法了

web server是用form post method讓使用者登入
wget --post-data="name=hello&pass=world" url
curl -d "name=hello&pass=world" url

由於登入資訊是用cookie紀錄 所以要將cookie儲存下來供爾後使用
[SAVE]
wget --keep-session-cookies --save-cookies file url
curl -c file url
[LOAD]
wget --load-cookies cookiefile url
curl -b cookiefile url

最後則是上傳檔案的關鍵了
wget只提供了plaintext的post method
還好curl對於multipart/form-data有特別支援
prefix@代表所要上傳的檔案
curl -F "name=hello" -F "passl=world" -F "file=@filename" url

附註一提: curl是一個snapshot url的工具
沒有辦法像wget一樣parse網頁內容並下載相關檔案