首页 > 解决方案 > 使用 POST 向服务器发送信息不适用于 curl 但适用于 netcat

问题描述

我有一个用 python 编写的小脚本,它充当服务器,仅在端口 443 上侦听应相应格式化的 POST 请求(这是文件的内容:testfile):

POST //[authority]/[path] HTTP/1.1
Host: [authority]
Content-length: [length]
[message-body]

当我尝试使用 netcat 发布 CSR 请求时,一切正常:

# ncat -v --ssl 192.168.0.1 443 < testfile
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Subject: CN=test-server
Ncat: Issuer: CN=test-server
Ncat: SHA-1 fingerprint: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Ncat: Certificate verification failed (self signed certificate).
Ncat: SSL connection to 192.168.0.1:443.
Ncat: SHA-1 fingerprint: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
HTTP/1.1 200 OK
text/html; charset=UTF-8
CSR file name: /opt/xxxx/xxx-xxx/xxx-queue/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem.csr
<h4>SUCCESS - CSR was uploaded, verified and stored</h4>
Ncat: 849 bytes sent, 199 bytes received in 0.02 seconds.

当我尝试使用 curl 进行操作时,它正在等待回复:

# curl -vkl -X POST \
     -H "User-Agent: " -H "Accept: " -H "Host: xxxx" \
     -H "Content-length: 688" -H "Expect: " -H "Content-Type:  " \
     -d @testfile https://192.168.0.1/

* About to connect() to 192.168.0.1 port 443 (#0)
*   Trying 192.168.0.1...
* Connected to 192.168.0.1 (192.168.0.1) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* skipping SSL peer certificate verification
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
*       subject: CN=test-server
*       start date: Apr 29 20:29:49 2018 GMT
*       expire date: Apr 26 20:29:49 2028 GMT
*       common name: test-server
*       issuer: CN=-test-server
> POST / HTTP/1.1
> Host: xxxxxxxxxx
> Content-length: 688
>
* upload completely sent off: 676 out of 676 bytes

它挂在这条消息上。不知道为什么。

请帮帮我。谢谢。

标签: curlposthttpsnetcat

解决方案


推荐阅读