Is it possible to send “OPTIONS *” with cURL?

2020-07-18 04:39发布

From RFC7230 Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing

When a client wishes to request OPTIONS for the server as a whole, as opposed to a specific named resource of that server, the client must send only "*" (%x2A) as the request-target.

To test how my site reacts I want to send the following request to the server.

OPTIONS * HTTP/1.1

I know I can use telnet, write my own client, etc. But I want to know if it's possible to do it with cURL?

Edit This can NOT be done with curl -X OPTIONS http://example.org, as suggested in a similar, but not identical, question That command will send OPTIONS http://example.org/ HTTP/1.1. I want to know if it's possible to send the asterisk with cURL.

标签: http curl
2条回答
我只想做你的唯一
2楼-- · 2020-07-18 05:04

Using -X OPTIONS only will send a slash and not an asterisk as path in the request.

In order to send a plain OPTIONS * to the server with curl, you need curl 7.55.0 or later and its --request-target option in addition to the -X flag. Used like this:

curl -X OPTIONS --request-target '*' https://example.com/
查看更多
劫难
3楼-- · 2020-07-18 05:05

You can send custom requests with cURL by using the -x option, https://curl.haxx.se/docs/manpage.html#-x

So this command would look like this

curl -X OPTIONS http://example.com
查看更多
登录 后发表回答