Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Capture HTTP Error in Perl

by hippo (Canon)
on Mar 26, 2014 at 18:08 UTC ( #1079847=note: print w/replies, xml ) Need Help??

in reply to Capture HTTP Error in Perl

There certainly is. Have a look at HTTP::Response, in particular the is_error and code methods.

Replies are listed 'Best First'.
Re^2: Capture HTTP Error in Perl
by suzun30 (Acolyte) on Mar 26, 2014 at 18:57 UTC

    Thanks for responding. If my understanding is right, I think I will be able to set the HTTP error code to a customized message . But I do not have the HTTP error code in the first place. I am looking at ways to first capture this. I tried the LWP:UserAgent, with the following code

    my $response = $ua->get('http://servername:84/dir/'); if($response->is_success){ }else{ die $response->status_line; }

    This returns me 401 - Not authorized error. I am using Win32::NetAdmin to authrize my user with the user login from env variable. How do I bypass this with the UserAgent module?

    Second question is, I get the error when I submit the page, how do I simulate this using the LWP::UserAgent ? My site has several perl scripts on the navigation menu which of which mine is one. I have given my specific .pl file name in the url. But it does not seem to authenticate it.

    Genuinely appreciate any feedback.

      The HTTP response code is just a number. It will be in the range 100 to 599 as given in the official IANA list. If you use LWP::UserAgent you can retrieve this number with the code method. If you should need to set the code (and I don't see why you should from what you've said so far) set it just to one of these integers and not to a message.

      I am using Win32::NetAdmin to authrize my user with the user login from env variable. How do I bypass this with the UserAgent module?

      I'm entirely unfamiliar with that module, and indeed with every module under Win32::* - you are on your own there. If it uses HTTP Basic Auth or if you supplant it with HTTP Basic Auth, then you could use the credentials method of LWP::UserAgent to authenticate.

        Hi hippo

        Thanks for the response. The Win32::netAdmin module basically verifies given the user id if he is part of a group who can access the site. My site is on a corporate intranet and needs to be authenticated via sso with no prompting for user id or password. The LWP::UserAgent module does seem to need the credentials aka the 'password' for the user to be authenticated I believe as far as I read through the documentation and in the http authentication methods .

        Bringing back to my original issue, I am just trying to capture the erratic 'Page cannot be displayed ' error here and tryin to figure out what is triggering it. Any experience with such a situation anyone? I am glad we have explored the known options so far. Appreciate any good advice. Thanks

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1079847]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-06-25 06:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.