-H, --header <header>


原生请求头

curl -v -X POST localhost:8081/health
image.png


自定义请求头

curl -v -X POST localhost:8081/health --header "X-Custom-Header;" --header "token:sneaky" --header "Host: baidu:8081" --header "User-Agent:"
image.png通过图片可观察到:

  • 可重写curl命令自带的请求头。curl命令内部自带的请求头Host: localhost:8081被修改成了Host: baidu:8081
  • 可移除curl命令自带的请求头。curl命令内部自带的请求头User-Agent: curl/8.0.1,被通过自定义请求头--header "User-Agent:"移除了。
  • 可自定义请求值为空的请求头。自定义请求头X-Custom-Header:是空值,通过设置请求头为:--header "X-Custom-Header;"
  • 可以同时添加多个自定义请求头。

    服务器后台输出

    image.png


  1. (HTTP) Extra header to use when getting a web page.
  2. You may specify any number of extra headers.
  3. Note that if you should add a custom header that has the same name as one of the internal ones curl would use, your externally set header will be used instead of the internal one. This allows you to make even trickier stuff than curl would normally do.
  4. You should not replace internally set headers without knowing perfectly well what you're doing.
  5. Remove an internal header by giving a replacement without content on the right side of the colon, as in: -H "Host:".
  6. If you send the custom header with no-value then its header must be terminated with a semicolon, such as -H "X-Custom-Header;" to send "X-Custom-Header:".
  7. curl will make sure that each header you add/replace is sent with the proper end-of-line marker, you should thus not add that as a part of the header content: do not add newlines or carriage returns, they will only mess things up for you.
  8. See also the -A, --user-agent and -e, --referer options.
  9. This option can be used multiple times to add/replace/remove multiple headers.

NewBie
10 声望0 粉丝

« 上一篇
mysql install
下一篇 »
curl -v, --verbose

引用和评论

0 条评论