我希望在Linux机箱上向Apache服务器发送一个标头。如何通过cURL调用实现这一点?
当前回答
我已经从curl转换为Httpie;语法如下:
http http://myurl HeaderName:value
其他回答
使用-H或--header。
手册页:http://curl.haxx.se/docs/manpage.html#-小时
男士卷发:
-H/--header <header>
(HTTP) Extra header to use when getting a web page. You may specify
any number of extra headers. 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. You should not replace internally set headers without
knowing perfectly well what you're doing. Remove an internal header
by giving a replacement without content on the right side of the
colon, as in: -H "Host:".
curl will make sure that each header you add/replace get 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.
See also the -A/--user-agent and -e/--referer options.
This option can be used multiple times to add/replace/remove multi-
ple headers.
示例1:单标题
curl --header "X-MyHeader: 123" www.google.com
示例2:多个标头
curl --header "Accept: text/javascript" --header "X-Test: hello" -v www.google.com
您可以看到curl通过添加-v选项发送的请求。
我已经从curl转换为Httpie;语法如下:
http http://myurl HeaderName:value
如果您想发送自定义标头,您可以这样做:
curl -v -H @{'custom_header'='custom_header_value'} http://localhost:3000/action?result1=gh&result2=ghk
我用邮差。
执行你想做的任何调用。然后,邮递员提供了一个方便的工具来显示curl代码。
在终端运行。
推荐文章
- 什么是HTTP“主机”报头?
- 在Bash中将输出赋给变量
- HTTPS和SSL3_GET_SERVER_CERTIFICATE:证书验证失败,CA is OK
- 自定义HttpClient请求头
- 过期和缓存控制头之间的区别是什么?
- REST DELETE真的是幂等的吗?
- 如何在Node.js内进行远程REST调用?旋度吗?
- 用户代理字符串可以有多大?
- 什么是接受* HTTP报头q=0.5 ?
- 缓存控制的无缓存和必须重新验证之间的区别?
- 如何为已安装的Ubuntu LAMP堆栈启用cURL ?
- 在PHP中为用户创建一个CSV文件
- Nginx中$host和$http_host的区别是什么
- 什么是http头“X-XSS-Protection”?
- 为什么cURL返回错误“(23)Failed writing body”?