对于"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. 【Web】Web开发中的异常处理方案

    我认为最合理的做法: 1.dao层不捕获异常.不抛出异常:spring框架将底层的数据库checked异常封装成unchecked异常了 2.service层捕获异常,并抛出自定义unchecked异 ...

  2. MySql.Data.dll的版本

    在.Net下访问Mysql,先是用6.4.4,老有问题,也不知道哪个版本可以用,查询官网 https://dev.mysql.com/doc/connector-net/en/connector-ne ...

  3. Velocity日期格式化

    1.pom.xml添加依赖 <dependency> <groupId>velocity-tools</groupId> <artifactId>vel ...

  4. AWStats日志分析系统

    1.什么是AWStats AWStats是一款功能强大且功能强大的免费工具,可以图形方式生成高级Web,流媒体,ftp或邮件服务器统计信息.此日志分析器用作CGI或命令行, 并在几个图形网页中显示您的 ...

  5. [Linux] - 利用ping给端口加密,限制访问

    Linux中,想对特定的端口加密访问,可以使用iptables的ping方式. 作用 访问被限制的端口,必需先ping发送对应的字节包(字节包大小可自行设置,此为密钥)才能访问成功! 下边是对SSH的 ...

  6. Nginx 反向代理504 Gateway Time-out

    location /ssfwpt { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_ ...

  7. settings设置中文admin

    所以更改setttings.py 下 LANGUAGE_CODE = 'zh-Hans'即可

  8. Linux 搭建git 自己拉取本地 git pull,其他地方的git仓库拉取代码

    Linux 下建立 Git 与 GitHub 的连接 Git 是一款开源的分布式版本控制系统,而 GitHub 是依托 Git 的代码托管平台. GitHub 利用 Git 极其强大的克隆和分支功能, ...

  9. spring 整合junit进行测试

    如果想让junit和spring容器环境无缝对接的话,可以使用如下方式: import com.jd.ptest.service.ICronService; import org.junit.Test ...

  10. 【Spark深入学习 -12】Spark程序设计与企业级应用案例02

    ----本节内容------- 1.遗留问题答疑 1.1 典型问题解答 1.2 知识点回顾 2.Spark编程基础 2.1 Spark开发四部曲 2.2 RDD典型实例 2.3 非RDD典型实例 3. ...