Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I get this error message when I run the below LWP code. Could someone help me to resolve this?

<font face="Arial" size=2>Exception occurred. </font> <p> <font face="Arial" size=2>/Submit/SubmitMain.asp</font><font face="Ari +al" size=2>, line 83</font>

Thanks for your help.

Regards,
Raja

Here is the code. -----------------------------------------------------------

#!/usr/bin/perl require 5; #use strict; use warnings; use HTTP::Request::Common qw(POST); use LWP::UserAgent; my $ua = LWP::UserAgent->new; $url ='http://xyz.com/Submit/SubmitMain.asp'; my $res = $ua->request(POST $url, Content_Type =>'form-data', Content => [ Location => 'MM02', Tickettype => '5120', CoreDirCorrect => 1, PhoneNumber => '12335656787', CustomerImpact => 3, 800014118 => 0, Severity => 'HIGH', InitialDescription => 'Test Request', SUBMIT1 => 'Submit Ticket Request']); # Check the outcome of the response if ($res->is_success) { print $res->content; } else { print "Bad luck this time\n\n"; print $res->as_string; }

20060315 Janitored by Corion: Added formatting, removed PRE tags

Replies are listed 'Best First'.
Re: Error while compiling LWP code
by ikegami (Patriarch) on Mar 15, 2006 at 20:35 UTC

    The error is from the SubmitMain.asp page. Assuming it works fine normally, it is not receiving something it is expecting to receive, or it is receiving something it doesn't expect to receive. We can't tell you what the problem is without knowing more about SubmitMain.asp.

    By the way, require 5; is rather useless since it occurs at run-time. use 5; is the compile-time equivalent.

    For future reference, place code in <c>...</c> tags when posting on Perlmonks. It will handle escaping, it will handle newlines, it will make your code easy to download, and it will handle wrapping when needed.

Re: Error while compiling LWP code
by InfiniteSilence (Curate) on Mar 15, 2006 at 19:44 UTC
    It's the square brackets.
    my $res = $ua->request(POST $url, [Content_Type =>'form-data', Content => '', Location => 'MM02', Tickettype => '5120', CoreDirCorrect => 1, PhoneNumber => '12335656787', CustomerImpact => 3, 800014118 => 0, Severity => 'HIGH', InitialDescription => 'Test Request', f=>'severalty', tmpl=>'severalty', SUBMIT1 => 'Submit Ticket Request']);
    Update: On second thought, maybe it isn't the brackets afterall. This seems to work fine for me as well:
    Content_Type =>'form-data', Content => [ Location => 'MM02' ...
    That'll teach me not to read the whole perldoc. For clarification...your error is happening in the Perl script, right?

    Celebrate Intellectual Diversity

      Not sure. Error could be while submitting data also.
Re: Error while compiling LWP code
by derby (Abbot) on Mar 15, 2006 at 20:37 UTC

    for request, you need to create the HTTP::Request object (and it's the first param) or use the convenience methods:

    my $ua = LWP::UserAgent->new; my $url = 'http://xyz.com/Submit/SubmitMain.asp'; my $res = $ua->post( $url, { Location => 'MM02', Tickettype => '5120', CoreDirCorrect => 1, PhoneNumber => '12335656787', CustomerImpact => 3, 800014118 => 0, Severity => 'HIGH', InitialDescription => 'Test Request', SUBMIT1 => 'Submit Ticket Request' } );

    -derby

        Doh!

        -derby