类似cURL的CLI的Go语言实现:bat

jopen 9年前
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.open-open.com/lib/view/home/1428629925046