|
|
| The stupid question is the question not asked | |
| PerlMonks |
Converting a curl cli to perl with curl2perl gives me painby bliako (Abbot) |
| on Jan 23, 2026 at 18:43 UTC ( [id://11167217]=perlquestion: print w/replies, xml ) | Need Help?? |
|
bliako has asked for the wisdom of the Perl Monks concerning the following question: It has been some time since I last used curl2perl (via Corion's HTTP::Request::FromCurl) and I remember it was working perfectly. Now, v0.55, it seems counter-intuitive how the curl's command-line parameters are passed. For example, how to convert this curl command coming out of FF developer tools?: curl 'https://example.com' -H 'User-Agent: Mozilla/5.0 (X11;)' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-GB,en;q=0.5'I tried: curl2perl 'https://example.com' -H 'User-Agent: Mozilla/5.0 (X11;)' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-GB,en;q=0.5'I gives me usage, confused by -H. Ok then let's add all that follows the url into double quotes: curl2perl 'https://example.com' "-H 'User-Agent: Mozilla/5.0 (X11;)' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-GB,en;q=0.5'"It thinks all headers are part of the first -H:
Changing quotes from single to double and vice-versa gives same result. What sort of works is when each curl parameter is quoted: curl2perl 'https://example.com' "-H 'User-Agent: Mozilla/5.0 (X11;)'" "-H 'Accept: application/json, text/plain, */*'" "-H 'Accept-Language: en-GB,en;q=0.5'"which gives this, notice the extraneous single-quotes:
But adding all these quotes is way too much work. Plus I am sure that I used it without having to quote anything. All I had to do was to remove the curl from the beginning of the command-line. Perhaps the Getopt::Long should be removed? What DOES WORK is diy:
(note: when omitting curl, it complains about Can't locate object method "host_port" via package "URI::_generic" ... HTTP/Request/CurlParameters.pm line 457., I mention it just in case this mis-usage reveals something more serious.) bonus b[au]g: request2perl is missing a use Pod::Usage;. I hope I am doing something wrong :) or else i write my own (that's a threat hehe :))
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||