首页 > 解决方案 > 使用 cURL 传输原始数据

问题描述

我需要将原始数据传输到没有 http-Server 的服务器。即它不理解 POST、PUT 或类似的命令。它只是侦听等待传入数据的端口,处理它们并将数据发回。顺便说一句:服务器正在侦听非标准端口,即 3500。

无论我在 cURL 中尝试了什么选项,我都无法正确传输数据。cURL 在发送实际数据之前总是至少发送一个“POST”或“PUT”。然后服务器用“……无效数据……”回复我。

我尝试过的选项:--data-raw、--data-binary、--upload-file、--raw,仅举几例。

是否有机会在 cURL 发送数据之前抑制“POST”或“PUT”的传输?

标签: curl

解决方案


i think this question is suitable for www.superuser.com rather than stackoverflow, and have voted to close it, but here goes:

this isn't a job for curl, it's a job for Netcat. use cat to read the file, and netcat to send the file and get the response, eg

cat file.ext | nc server.com 3500

(there are several netcat implementations, like the original *Hobbit*'s netcat, and GNU netcat, and *BSD netcat, i believe some netcat implementations need the syntax nc -p 3500 server.com instead, but if you're using GNU netcat, or Cygwin's netcat, or MacOS's netcat, the above syntax should work fine. for the record, many Linux systems ship with GNU netcat)

if you're on Windows, which doesn't ship with cat/netcat, you can install Cygwin which has both. MacOS and most Linux distros ship with netcat & cat by default.


推荐阅读