Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Capture HTTP Error in Perl

by suzun30 (Acolyte)
on Mar 26, 2014 at 18:57 UTC ( #1079850=note: print w/ replies, xml ) Need Help??


in reply to Re: Capture HTTP Error in Perl
in thread Capture HTTP Error in Perl

Hi,

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/AppPage.pl'); 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.


Comment on Re^2: Capture HTTP Error in Perl
Download Code
Re^3: Capture HTTP Error in Perl
by hippo (Curate) on Mar 26, 2014 at 23:20 UTC

    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://www.ietf.org/rfc/rfc2617.txt 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1079850]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2014-10-22 10:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (115 votes), past polls