I have this code that prints out a command and also runs it from Perl. When I run the curl command from Perl the remote server, queried from the curl request, complains about an HTTP 400 error.
When I run the same command, copied from the Perl print statement, it runs fine and returns a JSON string.
This behavior happens on Linux and Windows with Strawberry Perl. Any ideas?
Here is the code:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $command = <<'END';
curl 'https://tax-calculator-api.taxfoundation.org/taxcalc/tcja_submit
+' -H 'Origin: https://taxfoundation.org' -H 'Accept-Encoding: gzip, d
+eflate, br' -H 'Accept-Language: en-US,en;q=0.9' -H 'User-Agent: Mozi
+lla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
+ Gecko) Chrome/69.0.3497.100 Safari/537.36' -H 'content-type: applica
+tion/json' -H 'Accept: */*' -H 'Referer: https://taxfoundation.org/20
+18-tax-reform-calculator/' -H 'Connection: keep-alive' --data-binary
+$'{"filing_status": 1, "child_dep": 2, "nonchild_dep": 0, "ordinary_i
+ncome1": 150000, "ordinary_income2": 0, "business_income": 0, "ss_inc
+ome": 0, "qualified_income": 0, "401k_contributions": 0, "medical_exp
+enses": 0, "sl_income_tax": 0, "sl_property_tax": 0, "interest_paid":
+ 0, "charity_contributions": 0, "other_itemized": 0}' --compressed
END
print $command;
my $data = `$command` or die "$!\n";
print Dumper $data;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.