How to send multiline data to curl from a script?
Bo Berglund
bo.berglund at gmail.com
Fri Sep 3 16:33:04 UTC 2021
On Sat, 04 Sep 2021 01:03:15 +1000, Karl Auer <kauer at biplane.com.au> wrote:
>On Fri, 2021-09-03 at 16:42 +0200, Bo Berglund wrote:
>> How do I handle the line breaks in the curl call to the php script so
>> that the complete message will be read by the
>
>If you just want to spread the curl command over multiple lines neatly
>instead of having it all on one really long line you can do that by
>terminating partial lines with backslashes:
>
>
> curl --data "this" \
> --data "that" \
> --data "the other" \
> [etc]
>
>If you mean something else, then I don't understand the question :-)
>
>This works for any long command. It's safest to continue lines at
>whitespace, otherwise you will probably not get the results you expect.
>
Thanks, I was probably a bit unclear...
Say that I have a php script on a webserver and it processes POST data coming in
from a website form submission.
When the processing is done and the user entered items have been extracted I now
want to send the data via a call to a php script file on *another* webserver for
final handling like storage on a private database etc.
What I showed is an example of how the transfer to the final processing script
is done when I run a shellscript on a Linux machine to grab the data and send it
out using curl (which is mostly available on all Linuxes, but if not can be
installed).
This example is just to illustrate the way I want to transfer the form
submission data out of the first webserver.
The data at this step are separate entries with single words, and the work is
being done in a shellscript so I can easily call curl for that and I can
probably send multiline entries too using using something to represent line
breaks inside the call. But should that be \n or %xx% or what?
Note that the receiving php script expects POST (or can be changed to GET data
too) data with name=value pairs so my shellscript packages this as:
--data "addreth=$AddrEth"
Where addreth is the name of the item and $AddrEth is the variable holding the
value itself.
So now instead of in the Linux script the primary processing is in a php script
processing a form entry and it happens on the first webserver with user access.
And then I am inside of my php script on that server and need to send the data
on to the second server php script using some method that would work as curl
(which I do not think is available inside php).
And here too I need to know how to handle the line feeds..
So the question is really about two things:
1) What method inside php can I use to send a request to another server?
2) How do I escape line feeds in that call?
--
Bo Berglund
Developer in Sweden
More information about the ubuntu-users
mailing list