对于"User-Agent", "Cookie", "Host"这类标准的HTTP头部字段,通常会有另外一种设置方法。curl命令提供了特定的选项来对这些头部字段进行设置:
  • -A (or --user-agent): 设置 "User-Agent" 字段.
  • -b (or --cookie): 设置 "Cookie" 字段.
  • -e (or --referer): 设置 "Referer" 字段.
例如,以下两个命令是等效的。这两个命令同样都对HTTP头的"User-Agent"字符串进行了更改。
  1. $ curl -H "User-Agent: my browser" http://cnn.com
  2. $ curl -A "my browser" http://cnn.com
wget是另外一个类似于curl,可以用来获取URL的命令行工具。并且wget也一样允许你使用一个自定义的HTTP头。点击这里查看wget命令的详细信息。
 
GET:
with JSON:
curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://hostname/resource
with XML:
curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource
POST:
For posting data:
curl --data "param1=value1&param2=value2" http://hostname/resource
For file upload:
curl --form "fileupload=@filename.txt" http://hostname/resource
RESTful HTTP Post:
curl -X POST -d @filename http://hostname/resource
For logging into a site (auth):
curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login curl -L -b headers http://localhost/
 
-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
You can see the request that curl sent by adding the -v option.

curl HTTP Header的更多相关文章

  1. php curl 分离header和body信息

    php中可以通过curl来模拟http请求,同时可以获取http response header和body,当然也设置参数可以只获取其中的某一个.当设置同时获取response header和body ...

  2. PHP的curl查看header信息的功能(包括查看返回header和请求header)

    PHP的curl功能十分强大,简单点说,就是一个PHP实现浏览器的基础. 最常用的可能就是抓取远程数据或者向远程POST数据.但是在这个过程中,调试时,可能会有查看header的必要. 如下: ech ...

  3. php curl请求 header头携带参数

    $headers = array(    'api-key:'.$key,    'authorization:'.$authorization,      ); //初始化    $curl = c ...

  4. PHP curl post header

    第三方教程推荐:https://www.cnblogs.com/CHEUNGKAMING/p/5717429.html

  5. 浅谈 php 采用curl 函数库获取网页 cookie 和 带着cookie去访问 网页的方法!!!!

    由于近段时间帮朋友开发一个能够查询正方教务系统的微信公众平台号.有所收获.这里总结下个人经验. 开讲前,先吐槽一下新浪云服务器,一个程序里的   同一个函数  在PC测试可以正常运行,在它那里就会挂的 ...

  6. curl命令使用

    curl命令可以用来构造http请求.参数有很多,常用的参数如下: 通用语法:curl [option] [URL...]在处理URL时其支持类型于SHELL的名称扩展功能,如http://www.j ...

  7. php调用阿里大鱼 接口curl

    function http_request($url, $data = null, $header = null, $method = 'GET') { //如果是Get传参,拼接字符串 if ($m ...

  8. curl命令使用(转)

    转自:http://www.cnblogs.com/sunada2005/p/3829772.html curl命令可以用来构造http请求.参数有很多,常用的参数如下: 通用语法:curl [opt ...

  9. Linux curl命令参数详解

    笔者出处:http://www.aiezu.com/system/linux/linux_curl_syntax.html linux curl是通过url语法在命令行下上传或下载文件的工具软件,它支 ...

随机推荐

  1. iterm快捷键设置

    如图所示,选择相应的动作和快捷键组合

  2. apache配置伪静态Rewrite

    1: 修改apache的httpd.conf文件 找到这一行 #LoadModule rewrite_module modules/mod_rewrite.so 改成 LoadModule rewri ...

  3. asp.net mvc 实战化项目之三板斧

    laravel实战化项目之三板斧 spring mvc 实战化项目之三板斧 asp.net mvc 实战化项目之三板斧 接上文希望从一张表(tb_role_info 用户角色表)的CRUD展开asp. ...

  4. 时间序列分析 异常分析 stl

    https://blog.csdn.net/snowdroptulip/article/details/79125912 https://www.cnblogs.com/runner-ljt/p/52 ...

  5. 高仿MT4行情终端(K线图+操控+简单架构)

    技术:VS2015 Update3 + QT 5.11.2 + BOOST 1.68 + QT VS Tools + C++11   概述 模仿外汇MT4的界面 详细 代码下载:http://www. ...

  6. Jenkins持续集成 入门实践

    本文测试环境: ASP.NET MVC项目,Windows 7环境,SVN代码仓库, MSBuild,TortoiseSVN 持续集成这种工具很多了,Jenkins比较常用,他的原理就是一个服务,有一 ...

  7. Redis 学习之路 (011) - redis 多数据库

    一台服务器上都快开启200个redis实例了,看着就崩溃了.这么做无非就是想让不同类型的数据属于不同的应用程序而彼此分开. 那么,redis有没有什么方法使不同的应用程序数据彼此分开同时又存储在相同的 ...

  8. Vue $emit()不触发方法的原因

    vue使用$emit时,父组件无法触发监听事件的原因是: $emit传入的事件名称只能使用小写,不能使用大写的驼峰规则命名

  9. 性能测试相关(TPS/RT/PV等)(转)

    对于我们开发来说,我们日常最熟悉的工作就是把客户的需求实现并交付.但是,事情并不是往往就这样结束了,我们还需要后续对上线的系统进行跟踪调查,查看系统的运行情况.为什么呢?一方面,我们需要关注系统在运行 ...

  10. centos 环境搭建jenkins服务

    1.下载jenkins war包 https://jenkins.io/download/ 选择Generic Java package (.war)下载2.下载apache tomcat 8 htt ...