2013-05-11

Tcl upload file using HTTP PUT method

Tcl 要透過 HTTP PUT 上傳檔案可用 http 或 TclCurl,不過兩種方法送出的 header 與 body 有些不同,server 端自己寫的話要由 Content-Type 判斷 body 中資料段位置。

使用 Tcl http
package require http
set fd [open test.zip r]
set hd [::http::geturl "http://ios1.dslab.org/" -method PUT -binary 1 -querychannel $fd]
close $fd
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1) http/2.8.4 Tcl/8.6b3 
Accept-Encoding: deflate,gzip,compress 
Content-Type: application/x-www-form-urlencoded
Content-Length: 5538104 
使用 TclCurl
package require TclCurl
::curl::transfer -url "http://ios1.dslab.org/" -upload 1 -infile test.zip
Accept: */* 
Transfer-Encoding: chunked 
Expect: 100-continue
使用 Chrome Advanced REST client PUT 時的 header
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryvyHNXY3tzkHaqqv2 
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: Big5,utf-8;q=0.7,*;q=0.3

沒有留言:

張貼留言