例如,使用-v参数过帐到Web服务器: />没有提到我发布的数据。

cURL中是否有一个选项可以在输出中显示字符串“ firstname = john&lastname = doe”?

注意:显然,我想要的字符串在我执行的命令中,但是还有其他几个发布选项,例如--form和--data-ascii等。我想查看将原始数据发送到服务器。 br />

评论

您还可以运行tcpdump捕获要发送到服务器的实际数据。如果有的话,也可以使用wireshark(更好)。

我不确定你能做到。这是默默无闻的安全示例吗? -stackoverflow.com/questions/198462/…

#1 楼

我没有使用tcpdump得到的最接近的是使用--trace-ascii选项:

~ curl http://w3.org/ -d "hello=there" --trace-ascii /dev/stdout
== Info: About to connect() to w3.org port 80 (#0)
== Info:   Trying 128.30.52.45... == Info: connected
== Info: Connected to w3.org (128.30.52.45) port 80 (#0)
=> Send header, 210 bytes (0xd2)
0000: POST / HTTP/1.1
0011: User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.1
0051: 9.7 OpenSSL/0.9.8l zlib/1.2.3
0070: Host: w3.org
007e: Accept: */*
008b: Content-Length: 11
009f: Content-Type: application/x-www-form-urlencoded
00d0: 
=> Send data, 11 bytes (0xb)
0000: hello=there


不幸的是,这在您发布multipart/form-data时不起作用:

~ curl http://w3.org/ -F hello=there -F testing=123 --trace-ascii /dev/stdout
== Info: About to connect() to w3.org port 80 (#0)
== Info:   Trying 128.30.52.45... == Info: connected
== Info: Connected to w3.org (128.30.52.45) port 80 (#0)
=> Send header, 270 bytes (0x10e)
0000: POST / HTTP/1.1
0011: User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.1
0051: 9.7 OpenSSL/0.9.8l zlib/1.2.3
0070: Host: w3.org
007e: Accept: */*
008b: Content-Length: 244
00a0: Expect: 100-continue
00b6: Content-Type: multipart/form-data; boundary=--------------------
00f6: --------19319e4d1b79
010c: 
<= Recv header, 32 bytes (0x20)
0000: HTTP/1.1 301 Moved Permanently


评论


我知道这是您自己的答案,但我认为您可以接受此作为正确答案。无论如何它为我解决了,谢谢:-)

–达伦·库克(Darren Cook)
2012年5月6日在2:49

删除任何-v或--verbose,因为它们会覆盖trace指令。

– AlikElzin-kilaka
2014-2-17 14:56



@AugustinRiedinger与https可以正常工作。我只是尝试了一下,看到了有效载荷。数据已加密,但是由于您是连接的端点,因此您拥有所有可用数据,因此curl可以看到它。

– gak
14年8月29日在1:18

使用--trace-ascii在OS X 10.8.5 Mountain Lion上为我工作。我上传了一个包含两张图片和一个json正文的多部分表单实体,并且一切正常

–希思边界
2014年9月4日在21:13

代替--trace-ascii / dev / stdout,可以使用--trace-ascii-(破折号)

–亚当·米恰里克(Adam Michalik)
16-9-7上午11:40

#2 楼

或者您可以使用https://httpbin.org/

$ curl https://httpbin.org/post -d "firstname=john&lastname=doe"
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "firstname": "john", 
    "lastname": "doe"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "27", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.43.0"
  }, 
  "json": null, 
  "origin": "*.*.*.*", 
  "url": "https://httpbin.org/post"
}

进行测试

#3 楼

想添加netcat替代

#!/bin/bash
nc -l 8080 &

curl "http://localhost:8080" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
--data @<(cat <<EOF
{
  "me": "$USER",
  "something": $(date +%s)
}
EOF
)


#4 楼

您可以使用Charles和curl --proxy localhost:8888。简单!

评论


不,它不适用于https。接受的答案很好而且更容易。

–akostadinov
15年5月18日在20:41

https不是问题中的必要条件:p

–多里
2015年5月19日上午10:11

@CasparHarmer接受的答案是什么概率?如果您需要更多,TCPdump可以处理。

–外观
17年6月20日在12:55

这发生在3年前。我记不起来。

–卡斯珀·哈默(Caspar Harmer)
17年6月20日在16:12

#5 楼

--trace -与curl 7.58配合使用,并向您显示POST正文:
$ curl --trace - -d 'foo=bar' http://example.org
== Info: Rebuilt URL to: http://example.org/
== Info:   Trying 2606:2800:220:1:248:1893:25c8:1946...
== Info: TCP_NODELAY set
== Info: Connected to example.org (2606:2800:220:1:248:1893:25c8:1946) port 80 (#0)
=> Send header, 144 bytes (0x90)
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 65 78 61 6d 70 6c 65 2e 6f .Host: example.o
0020: 72 67 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a 20 rg..User-Agent: 
0030: 63 75 72 6c 2f 37 2e 35 38 2e 30 0d 0a 41 63 63 curl/7.58.0..Acc
0040: 65 70 74 3a 20 2a 2f 2a 0d 0a 43 6f 6e 74 65 6e ept: */*..Conten
0050: 74 2d 4c 65 6e 67 74 68 3a 20 37 0d 0a 43 6f 6e t-Length: 7..Con
0060: 74 65 6e 74 2d 54 79 70 65 3a 20 61 70 70 6c 69 tent-Type: appli
0070: 63 61 74 69 6f 6e 2f 78 2d 77 77 77 2d 66 6f 72 cation/x-www-for
0080: 6d 2d 75 72 6c 65 6e 63 6f 64 65 64 0d 0a 0d 0a m-urlencoded....
=> Send data, 7 bytes (0x7)
0000: 66 6f 6f 3d 62 61 72                            foo=bar
== Info: upload completely sent off: 7 out of 7 bytes
<= Recv header, 17 bytes (0x11)
0000: 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d HTTP/1.1 200 OK.
0010: 0a                                              .
<= Recv header, 22 bytes (0x16)