How to send multiline data to curl from a script?
Bo Berglund
bo.berglund at gmail.com
Sat Sep 4 09:42:13 UTC 2021
On Sat, 04 Sep 2021 10:16:07 +1000, Karl Auer <kauer at biplane.com.au> wrote:
>On Fri, 2021-09-03 at 18:33 +0200, Bo Berglund wrote:
>> 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.
>
>You could build a curl command line and run it from PHP via system(),
>exec(), shell_exec(), passthru() or even proc_open()/popen().
I am not sure the web provider (Network Solutions) will allow that since they
obviously also have banned the mail() function in php...
>Alternatively, google "send data with post in php" or similar - I'm no
>PHP guy, so can't help further with that, but I found lots of very
>plausible looking ideas.
>
(I realize that this is probably not the right place to discuss PHP questions,
but I know no other place for Linux/Apache related questions so I chanced a
try...)
Yes, I will try that google route too. So far my googling has only turned up old
posts which I believe are not addressing the current situation with more of
locked down web functionality.
One example from the PHP 8 manual page regarding curl-init
https://www.php.net/manual/en/function.curl-init.php
"On recent distributions CURL and PHP support for CURL have not been included in
the main product. In particular in recent distributions of Ubuntu Linux CURL
and PHP support for CURL are not even available from the official repositories.
The steps to incorporate support are complex and require adding a non-standard
repository. It is therefore advisable for programmers to rewrite code to use
the stream interface to access resources across the Internet."
The workaround example shown then I don't understand, though...
This means that I am probably out of luck concerning using curl in php on the
webhotel used.
BTW:
Regarding the subject question about multiline handling I found this page
describing how to encode special chars in URL strings:
https://en.wikipedia.org/wiki/Percent-encoding#Character_data
So by replacing all newlines with %0A the multiline text is converted to a
single line string but the new lines will be detected in the receive end.
Spaces are ok in the curl call since the parameter is quoted.
I have tested that this works:
curl --data "item=20 lb of flour%0A12 oz of Salt"
http://somedomain.com/php/test.php
This creates one item server side that contains a 2-line text:
20 lb of flour
12 oz of Salt
--
Bo Berglund
Developer in Sweden
More information about the ubuntu-users
mailing list