我尝试使用带有--data-urlencode
的curl
对查询参数进行URL编码,但它们最终被附加到查询中,就像--data
一样。
这个问题可以在netcat的帮助下重现,并对其进行查询。
curl
POST查询示例:
curl --data-urlencode "foo=bar" 127.0.0.1:8080/test/path
实际输出:
$ nc -l 8080
POST /test/path HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: curl/7.58.0
Accept: */*
Content-Length: 7
Content-Type: application/x-www-form-urlencoded
foo=bar
预期输出:
$ nc -l 8080
POST /test/path?foo=bar HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: curl/7.58.0
Accept: */*
发布于 2019-11-16 06:48:03
根据manual的说法,--data-urlencode
选项"...posts data,类似于其他数据,-d选项“。所以,如果你看到一个帖子,这是预期的行为。
您可以使用--get
让curl发出GET请求。此外,-v
也是一个好朋友!
curl -v --data-urlencode "foo=bar" http://127.0.0.1/test.php
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> POST /test.php HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 7
> Content-Type: application/x-www-form-urlencoded
使用--get
curl -v --get --data-urlencode "foo=bar" http://127.0.0.1/test.php
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET /test.php?foo=bar HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/7.47.0
> Accept: */*
https://stackoverflow.com/questions/58874140
复制相似问题