·  PERL – HTTP Request – Create – GET


- Info:

  - This tutorial shows how to create GET HTTP Request.


- Procedure:

  - Create "PERL Console Application" Test.pl.

  - Create "PERL Web Application" Test.plex.



    use LWP::Simple;

    print get("http://localhost/test.plex?name=Jack^age=30");

    print get("http://localhost/test.html");



    print("Content-type: text/html\n\n");

    print("Hello from PLEX!");



    Hello from HTML!


- Errors:

  - Nothing is returned but I can get the page through Internet Explorer.

  - In IE proxy is defined in:

    - Tools – Internet Options – Connections – LAN Settings – Proxy Server

    - Address:   myproxy.hr

    - Port:    8080

  - If your computer is behind proxy then you need to defined it when fetching world wide web pages.

  - This can't be done with LWP::Simple so you have to use LWP::UserAgent.

  - Define environment variable HTTP_proxy=http://myproxy.hr:8080 and tell perl to use it as shown in yellow.

    use LWP::UserAgent;


    my $ua = LWP::UserAgent->new;



    my $response = $ua->get('http://www.hnb.hr/tecajn/hvazeca.htm');


    if   ($response->is_success) { print $response->content;   }

    else                         { die $response->status_line; }