1

I am trying to post data to a page with Perl, but the page also requires headers. How would I post the headers and send headers (cookies, user agents, etc)?

I tried using LWP::UserAgent, but I couldn't figure out how to send the headers even though I could post to the page.

One more thing about this topic. When I posted on that page and printed the response content I could see the html just fine except the numbers that were supposed to show.

1 Answer 1

4

Try doing this :

use LWP::UserAgent;
use HTTP::Request;

my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(
    POST => "http://domain.tld/path"
);
$request->content("stuff=foobar");
$request->content_type("application/x-www-form-urlencoded");
my $response = $userAgent->request($request);

if ($response->code == 200) {
    print $response->as_string;
}
else {
   die $response->status_line;
}
Sign up to request clarification or add additional context in comments.

1 Comment

$userAgent is not defined. Please fix the response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.