#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    5
    Rep Power
    0

    Unhappy Request Via Http


    I need to send the request via a socket, but I am unable to get a response from the server. Can anyone tell me where is the error?

    An example of what I send requisition is: Example: http: / / api.ipaddresslabs.com/iplocation/v1.7/locateip key = demo & ip = 201.8.212.28 & format = XML?. Via browser it works correctly, but in code, no!

    My answer is the script: HTTP/1.1 504 Gateway Timeout.


    #!/usr/bin/perl -w
    use IO::Socket;
    $remote = IO::Socket::INET->new( Proto => "tcp",
    PeerAddr => "api.ipaddresslabs.com",
    PeerPort => "http(80)",
    );
    unless ($remote) { die "cannot connect to http daemon o"; }
    $remote->autoflush(1);
    print $remote "GET /iplocation/v1.7/locateip?key=demo&ip=179.192.66.169&format=XML HTTP/1.1\n\n";
    while ( <$remote> ) { print; }
    close $remote;
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    Why not simplify the process by using LWP::Simple?

    This works for me:
    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use LWP::Simple;
    
    my $url = 'http://api.ipaddresslabs.com/iplocation/v1.7/locateip?key=demo&ip=179.192.66.169&format=XML';
    getprint $url;
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    5
    Rep Power
    0

    Thanks!


    Gee, thanks a lot! It is that I am new to perl, and has many modules that do not know well! But it was, it worked fine!

IMN logo majestic logo threadwatch logo seochat tools logo