Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send empty HTTP header with libcurl

Tags:

curl

libcurl

I want to add an empty header in my HTTP packet. Something like:

Someheader:

But I see that libcurl does not support that. They propose a workaround by concatenating the empty header with another header:

"Someheader:\r\nheader1: value"

Does the latest libcurl offer another — more proper — way to send an empty header?

like image 757
MOHAMED Avatar asked Oct 02 '15 14:10

MOHAMED


People also ask

Can a HTTP header be empty?

An empty header is valid according to the HTTP specs, so ASP.NET Core shouldn't remove it. Anyway, there's an easy workaround to prevent empty headers from being removed: instead of setting the header to an empty string, set it to a string containing only whitespace: Response.

How do I send headers in curl?

To send an HTTP header with a Curl request, you can use the -H command-line option and pass the header name and value in "Key: Value" format. If you do not provide a value for the header, this will remove the standard header that Curl would otherwise send.

How do I pass multiple headers in curl command?

To pass multiple headers in a curl request you simply add additional -H or --header to your curl command. For standard HTTP header fields such as User-Agent, Cookie, Host, there is actually another way to setting them.


1 Answers

Per an example on the libcurl site, you can replace the colon with a semicolon. That will expand into an empty header. So:

Someheader;

will actually be sent as:

Someheader: 
like image 58
Paul Roub Avatar answered Oct 11 '22 18:10

Paul Roub