如何使用curl发送文件到服务器? [英] How to send a file to a server using curl?

查看:482
本文介绍了如何使用curl发送文件到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我知道草皮所有关于卷曲的平方根,我并不想了解它。有人告诉我可能帮我在一些C code,其中我试图将数据写入到Apache服务器跟踪问题。我可能会吠叫的完全的那木错在这里。

First off, I know the square root of sod all about curl and I'm not trying to learn it. I'm told it might help me out tracking down a problem in some C code where I am trying to write data to an Apache server. I may be barking up completely the wrong tree here.

我想要做的是做从我的笔记本电脑到我的桌面是运行在HTTP服务器的HTTP POST,所以希望看到完全原始的HTTP会是什么样子使用Wireshark的。然后,我可以回到C code对我的嵌入式主板与如何获取工作更好的主意。

What I want to do is to do an HTTP POST from my laptop to my desktop which is running the HTTP server, so hopefully see exactly what the raw HTTP would look like using Wireshark. Then I can go back to the C code on my embedded board with a better idea of how to get that working.

我曾尝试下面的命令:

curl -X POST -d @test.txt 192.168.0.106/incoming

在哪里的text.txt只包含Hello World的纯文本(用vim创建)。 0.106是Apache服务器...它与一个GET命令很好地提供文件。

Where text.txt just contains "Hello World" in plain text (created with vim). .106 is the Apache server...which serves files nicely with a GET command.

但是,这给了:

Warning: Couldn't read data from file "test.txt", this makes an empty POST.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://192.168.0.106/incoming/">here</a>.</p>
</body></html>

非常感谢!

推荐答案

您想从你的笔记本电脑到Apache服务器发送一些数据并保存的内容在传入文件夹中。

My Understanding:

You want to send some data from your Laptop to the Apache Server and save the contents in the incoming folder.

对于这一点,你需要的的东西来接收数据您是从卷曲发送。我建议你​​创建一个的index.php 传入文件夹内。根据您使用curl命令,你可以有这样的事情在的index.php

For this, you will need something to receive the data that you are sending from Curl. I would suggest that you create an index.php inside your incoming folder. Depending on the curl command that you are using, you can have something like this in index.php.

的index.php

index.php

<?PHP
 move_uploaded_file($_FILES['content']['tmp_name'], "test.txt");
?>

如果你要使用:

curl --form "content=@test.txt" http://192.168.0.106/incoming/

否则,做这样的事情:

Otherwise, do something like this:

的index.php

index.php

<?PHP
file_put_contents("test2.txt", $_POST['content']);
?>

curl --data-urlencode "content@test.txt" http://192.168.0.106/incoming/

这篇关于如何使用curl发送文件到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆