0

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.

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.

I have tried the following command:

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

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.

But that gives:

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>

Many thanks!

DiBosco
  • 838
  • 8
  • 21

1 Answers1

2

My Understanding:

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

How to do this:

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

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

if you are going to use:

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

Otherwise, do something like this:

index.php

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

with

curl --data-urlencode "content@test.txt" http://192.168.0.106/incoming/
kums
  • 2,661
  • 2
  • 13
  • 16
  • 1
    That's essentially what I want to do; however, with this reply I think you have just answered a question I was finally starting to wonder about. I had assumed that you could just POST a file to an Apache server and it would accept it and store it on the server's hard drive. I am now thinking that is not possible, not part of what an HTTP server must be able to do by default and that you do, indeed, have to have a script or program running on the server to take the HTTP POST data and do something with it. – DiBosco Nov 19 '14 at 18:02