如何删除cURL发送的默认标头? [英] How can I remove default headers that cURL sends?

查看:113
本文介绍了如何删除cURL发送的默认标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,Curl添加标头,例如 Content-type User-agent .通常,这是一件好事,但当这些标头丢失时,我正在尝试测试服务器的工作.

Curl by default adds headers such as Content-type and User-agent. Normally that is a good thing but I'm trying to test what our server does when those headers are missing.

我的问题是 Content-type 标头.如果丢失,服务器将正确假定用户已发送JSON.但是,curl实际上会添加缺少的标题,并错误地假定我发布的内容是 application/x-www-form-urlencoded .它还发送/的Accept标头.

My problem is with the Content-type header. If it is missing, the server correctly assumes the user sent JSON. However, curl actually adds the missing header and incorrectly assumes that the content I am posting application/x-www-form-urlencoded. It also sends an Accept header of / .

我想这是很好的默认行为,但是我基本上希望它不发送我未指定的标头.有选择吗?

I suppose that is nice default behavior but I basically would like it to not send headers I did not specify. Is there an option for that?

curl -v -X POST 'https://example.com' -d '{...}'

> User-Agent: curl/7.37.1
> Host: domain.com
> Accept: */*
> Content-Length: 299
> Content-Type: application/x-www-form-urlencoded

推荐答案

在要删除的标头中使用 -H 标志,并且在:

Use -H flag with the header you want to remove and no content after the :

-H, --header LINE   Custom header to pass to server (H)

样品

-H 'User-Agent:'

这将使请求 没有 成为 User-Agent 标头(而不是发送带有空值的报头)

This will make the request without the User-Agent header (instead of sending it with an empty value)

这篇关于如何删除cURL发送的默认标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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