卷曲-我们如何获得POST请求消息?

时间:2019-09-13 01:59:59

标签: curl request httprequest httpresponse

我们如何在终端上获取带有curl的POST 请求消息

如果我是对的,这就是我们获得回复消息的方式:

$ curl -X POST -d "param1=value1&param2=value2" 'http://example.com' -i
HTTP/1.1 200 OK
Date: Fri, 13 Sep 2019 01:51:22 GMT
Server: Apache/2.4.38 (Ubuntu)
Content-Length: 56
Content-Type: text/html; charset=UTF-8

Array
(
    [param1] => value1
    [param2] => value2
)

我们如何在下面得到类似的东西?

POST /path HTTP/1.1
Host: example.com

foo=bar&baz=bat

使用-v:

$ curl -X POST -d "param1=value1&param2=value2" 'http://127.0.0.1' -v

* Expire in 0 ms for 6 (transfer 0x5591f30695c0)
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x5591f30695c0)
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> POST / HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/7.64.0
> Accept: */*
> Content-Length: 27
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 27 out of 27 bytes
< HTTP/1.1 200 OK
< Date: Fri, 13 Sep 2019 01:41:44 GMT
< Server: Apache/2.4.38 (Ubuntu)
< Content-Length: 56
< Content-Type: text/html; charset=UTF-8
<
Array
(
    [param1] => value1
    [param2] => value2
)
* Connection #0 to host 127.0.0.1 left intact

但是看不到没有请求消息。

1 个答案:

答案 0 :(得分:3)

https://curl.haxx.se/docs/manpage.html#--trace

=> Send header, 143 bytes (0x8f)
0000: 50 4f 53 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d POST / HTTP/1.1.
0010: 0a 48 6f 73 74 3a 20 31 32 37 2e 30 2e 30 2e 31 .Host: 127.0.0.1
0020: 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a 20 63 75 ..User-Agent: cu
0030: 72 6c 2f 37 2e 36 36 2e 30 0d 0a 41 63 63 65 70 rl/7.66.0..Accep
0040: 74 3a 20 2a 2f 2a 0d 0a 43 6f 6e 74 65 6e 74 2d t: */*..Content-
0050: 4c 65 6e 67 74 68 3a 20 32 37 0d 0a 43 6f 6e 74 Length: 27..Cont
0060: 65 6e 74 2d 54 79 70 65 3a 20 61 70 70 6c 69 63 ent-Type: applic
0070: 61 74 69 6f 6e 2f 78 2d 77 77 77 2d 66 6f 72 6d ation/x-www-form
0080: 2d 75 72 6c 65 6e 63 6f 64 65 64 0d 0a 0d 0a    -urlencoded....
=> Send data, 27 bytes (0x1b)
0000: 70 61 72 61 6d 31 3d 76 61 6c 75 65 31 26 70 61 param1=value1&pa
0010: 72 61 6d 32 3d 76 61 6c 75 65 32                ram2=value2
== Info: upload completely sent off: 27 out of 27 bytes

https://curl.haxx.se/docs/manpage.html#--trace-ascii

=> Send header, 143 bytes (0x8f)
0000: POST / HTTP/1.1
0011: Host: 127.0.0.1
0022: User-Agent: curl/7.66.0
003b: Accept: */*
0048: Content-Length: 27
005c: Content-Type: application/x-www-form-urlencoded
008d:
=> Send data, 27 bytes (0x1b)
0000: param1=value1&param2=value2
== Info: upload completely sent off: 27 out of 27 bytes