HTTP::Request::CurlParameters - container for a Curl-like HTTP request
my $ua = LWP::UserAgent->new; my $params = HTTP::Request::CurlParameters->new(argv => \@ARGV); my $response = $ua->request($params->as_request);
Objects of this class are mostly created from HTTP::Request::FromCurl. Most likely you want to use that module instead:
my $ua = LWP::UserAgent->new; my $params = HTTP::Request::FromCurl->new(command_curl => $cmd); my $response = $ua->request($params->as_request);
->new
Options:
method
method => 'GET'
The HTTP method to use.
uri
uri => 'https://example.com'
The URI of the request.
headers
headers => { 'Content-Type' => 'text/json', 'X-Secret' => ['value-1', 'value-2'], }
The headers of the request. Multiple headers with the same name can be passed as an arrayref to the header key.
cookie_jar
The cookie jar to use.
cookie_jar_options
Options for the constructor of the cookie jar.
credentials
credentials => 'hunter2:secret'
The credentials to use for basic authentication.
auth
auth => 'basic'
The authentication method to use.
post_data
post_data => ['A string','across multiple','scalars']
The POST body to use.
body
body => '{"greeting":"Hello"}'
The body of the request.
timeout
timeout => 50
The timeout for the request
unix_socket
unix_socket => '/var/run/docker/docker.sock'
form_args
The HTML form parameters. These get converted into a body.
insecure
insecure => 1
Disable SSL certificate verification
cert
cert => '/path/to/certificate',
Use the certificate file for SSL
capath
capath => '/path/to/cadir/',
Use the certificate directory for SSL
output
Name of the output file
show_error
show_error => 0
Show error message on HTTP errors
fail
fail => 1
Let the Perl code die on error
die
->as_request
$ua->request( $r->as_request );
Returns an equivalent HTTP::Request object
$r->as_request
my $r = $curl->as_request;
Returns a HTTP::Request object that represents the Curl options.
$r->as_snippet( %options )
print $r->as_snippet( type => 'LWP' );
Returns a code snippet that returns code to create an equivalent HTTP::Request object and to perform the request using WWW::Mechanize.
This is mostly intended as a convenience function for creating Perl demo snippets from curl examples.
curl
Arrayref of headers that will not be output.
Convenient values are ['Content-Length']
type => 'Tiny',
Type of snippet. Valid values are LWP for LWP::UserAgent and Tiny for HTTP::Tiny.
LWP
Tiny
$r->as_curl
print $r->as_curl;
Returns a curl command line representing the request
This is convenient if you started out from something else or want a canonical representation of a curl command line.
The curl command to be used. Default is curl.
$r->clone
Returns a shallow copy of the object
The public repository of this module is http://github.com/Corion/HTTP-Request-FromCurl.
The public support forum of this module is https://perlmonks.org/.
Please report bugs in this module via the Github bug queue at https://github.com/Corion/HTTP-Request-FromCurl/issues
Max Maischein corion@cpan.org
corion@cpan.org
Copyright 2018-2022 by Max Maischein corion@cpan.org.
This module is released under the same terms as Perl itself.
To install HTTP::Request::FromCurl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Request::FromCurl
CPAN shell
perl -MCPAN -e shell install HTTP::Request::FromCurl
For more information on module installation, please visit the detailed CPAN module installation guide.