類似cURL的CLI的Go語言實現:bat

jopen 9年前發布 | 18K 次閱讀 網絡工具包 BAT
CLI的Go語言實現,類似于cURL的工具。Bat能夠用于測試、調試和與HTTP服務器交互。

主要特性

  • 直觀的語法
  • 內置JSON 支持
  • 支持表單提交和文件上傳
  • HTTPS, proxies, and authentication
  • 任意請求數據
  • 自定義headers

安裝

go get -u github.com/astaxie/bat

make sure the$GOPATH/binis added into$PATH

使用

Hello World:

$ bat beego.me

Synopsis:

bat [flags] [METHOD] URL [ITEM [ITEM]]

See alsobat --help.

示例

Custom HTTP method, HTTP headers and JSON data:

$ bat PUT example.org X-API-Token:123 name=John

Submitting forms:

$ bat -form=true POST example.org hello=World

See the request that is being sent using one of the output options:

$ bat -v example.org

Use Github API to post a comment on an issue with authentication:

$ bat -a USERNAME POST https://api.github.com/repos/astaxie/bat/issues/1/comments body='bat is awesome!'

Upload a file using redirected input:

$ bat example.org < file.json

Download a file and save it via redirected output:

$ bat example.org/file > file

Download a file wget style:

$ bat --download example.org/file

Set a custom Host header to work around missing DNS records:

$ bat localhost:8000 Host:example.com

Following is the detailed documentation. It covers the command syntax, advanced usage, and also features additional examples.

HTTP 方法

The name of the HTTP method comes right before the URL argument:

$ bat DELETE example.org/todos/7

which looks similar to the actual Request-Line that is sent:

DELETE /todos/7 HTTP/1.1

When the METHOD argument is omitted from the command, bat defaults to either GET (if there is no request data) or POST (with request data).

項目主頁:http://www.baiduhome.net/lib/view/home/1428629925046

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!