curl - 使用 cURL 传输原始数据
问题描述
我需要将原始数据传输到没有 http-Server 的服务器。即它不理解 POST、PUT 或类似的命令。它只是侦听等待传入数据的端口,处理它们并将数据发回。顺便说一句:服务器正在侦听非标准端口,即 3500。
无论我在 cURL 中尝试了什么选项,我都无法正确传输数据。cURL 在发送实际数据之前总是至少发送一个“POST”或“PUT”。然后服务器用“……无效数据……”回复我。
我尝试过的选项:--data-raw、--data-binary、--upload-file、--raw,仅举几例。
是否有机会在 cURL 发送数据之前抑制“POST”或“PUT”的传输?
解决方案
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.
推荐阅读
- c++ - Fstream 无法识别相对路径
- spring-boot - Spring Boot 应用程序在 tomcat 服务器中无法正常工作
- reactjs - 在 useCallback 中调用 setState 时防止无限循环
- sqlite - 编写触发器以防止使用 sqlite 删除某些行
- c# - 仅显示特定行中包含特定值的行
- c# - 所有派生窗体的 WindowState 都在一起变化
- logging - 记录器在 Cloudwatch 上创建空日志
- c++ - 我们可以在不使用虚函数的情况下根据它们的参数调用覆盖函数吗?
- parallel-processing - 为什么原子操作仅适用于 HLSL 计算着色器中的线程组?
- ruby-on-rails - 在入口脚本中捆绑安装和纱线安装 - Docker