API-Eulerian
view release on metacpan or search on metacpan
lib/API/Eulerian/EDW/Request.pm view on Meta::CPAN
# @param $type - Data type of POST request
# @param $file - Local file path used to store HTTP reply.
#
# @return API::Eulerian::EDW::Status instance.
#
use Data::Dumper;
sub _request
{
my ( $class, $method, $url, $headers, $what, $type, $file ) = @_;
my $status = API::Eulerian::EDW::Status->new();
my $endpoint;
my $request;
# Ensure default type
$type = $type || 'application/json';
# Sanity check POST arguments
if( $method eq 'POST' ) {
if( ! ( defined( $what ) && defined( $type ) ) ) {
$status->error( 1 );
$status->msg( "Mandatory argument to post request is/are missing" );
lib/API/Eulerian/EDW/Request.pm view on Meta::CPAN
# Setup Content_Length and Content_Type
$headers->push_header( Content_Length => length( $what ) );
$headers->push_header( Content_Type => $type );
}
}
# Create HTTP Request
$request = HTTP::Request->new( $method, $url, $headers, $what );
# Create End Point used to communicate with remote server
$endpoint = LWP::UserAgent->new(
keep_alive => 0,
cookie_jar => {},
ssl_opts => {
SSL_verifycn_publicsuffix => '',
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
verify_hostname => 0,
SSL_hostname => '',
},
);
# Increase Read Timeout on TCP socket to avoid being disconnected
$endpoint->timeout( 1800 );
# Send Request, wait response if file is defined reply content is
# writen into local file.
my $response = $endpoint->request( $request, $file );
my $json = API::Eulerian::EDW::Request->json( $response );
$status->{ response } = $response;
if( $response->code != HTTP_OK ) {
$status->error( 1 );
$status->code( $response->code );
$status->msg(
defined( $json ) ?
encode_json( $json ) : $response->content()
( run in 0.265 second using v1.01-cache-2.11-cpan-27979f6cc8f )