如何通过curl调用使用HTTP请求发送头? [英] How to send a header using a HTTP request through a curl call?

查看:361
本文介绍了如何通过curl调用使用HTTP请求发送头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Linux盒子上向我的Apache服务器发送一个头。如何通过curl调用来实现这一点?

I wish to send a header to my Apache server on a Linux box. How can I achieve this via a curl call?

推荐答案

man curl

   -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.



示例:



Example:

curl --header "X-MyHeader: 123" www.google.com

您可以通过添加 -v 选项来查看curl发送的请求。

You can see the request that curl sent by adding the -v option.

这篇关于如何通过curl调用使用HTTP请求发送头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆