如何从 Linux 命令行使用 curl 发送数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6865146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:20:08  来源:igfitidea点击:

How to send data using curl from Linux command line?

linuxbashcurlwifi

提问by Ankur Agarwal

I am trying to transmit data out of an embedded Linux device over the wifi connection. I have curl and wget on the device. How would I transmit data out of the device using curl or wget ? Any pointers welcome.

我正在尝试通过 wifi 连接从嵌入式 Linux 设备传输数据。我在设备上有 curl 和 wget。如何使用 curl 或 wget 将数据传输出设备?欢迎任何指点。

采纳答案by Micha? ?rajer

there is a "--post-file" option in wget:

wget 中有一个“--post-file”选项:

wget --post-file=filetoSend URL

回答by marcelog

this is a get: curl "http://www.google.com/?hl=en&q=search"

这是一个获取:curl "http://www.google.com/?hl=en&q=search"

for a post you have to use the option "-d" and specify the key=value variables

对于帖子,您必须使用选项“-d”并指定 key=value 变量

回答by das_weezul

Try netcat, the swiss-army-knife for sending receiving data using the console ;). Some examples covering common use-cases can be found here: http://www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples/

试试 netcat,瑞士军刀,用于使用控制台发送接收数据;)。可以在此处找到一些涵盖常见用例的示例:http: //www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples/

Sending a file:

发送文件:

On your embedded device start serving content on port 3333:

在您的嵌入式设备上开始在端口 3333 上提供内容:

cat myfile.txt | nc -l 3333

On your PC start listening on port 3333 and dump data into a file:

在您的 PC 上开始侦听端口 3333 并将数据转储到文件中:

nc <ip-of-embedded-device> 3333 > receivedData.txt

回答by Satyajit

If it is only (key,value) pairs that you want to send then

如果您只想发送(键,值)对,那么

curl -d key1=value1 -d key2=value2 <URL>

But if it is some file that you want to send then

但是如果你想发送某个文件,那么

curl --data-binary @<file path> <URL>