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

I am trying to set a send a session id to a webpage. I am not sure what's wrong. The connection is failing and I am getting the response as C:\Automation\API_Test\API_Test\Scripts>perl cookies.pl fail 500 at cookies.pl line 22.

Could you please help.
#!/usr/bin/perl -l use LWP::UserAgent; use HTTP::Cookies; # sending cookies as a part of header $sessionKey = "session"; $sessionId = "1399663809196"; my $ua = LWP::UserAgent->new; $request = HTTP::Request->new(POST => 'https://localhost:4096/CVTLAPI/ +DV/libraries/15.154.52.112'); my $cookies = HTTP::Cookies->new(); $cookies->set_cookie(0,'session',$sessionId); $ua->cookie_jar($cookies); $response = $ua->request($request); if($response->is_success){ print "sucess\n"; print $response->code; } else { print "fail\n"; die $response->code; }

Replies are listed 'Best First'.
Re: Rest API testing with perl
by moritz (Cardinal) on May 11, 2014 at 19:07 UTC

    The return code 500 doesn't mean that there's a problem with the connection, but rather that your request triggered an internal error in the web application you're testing.

    So look at that web application's error log, it should give you more clues about what's going wrong.

Re: Rest API testing with perl
by hippo (Archbishop) on May 11, 2014 at 19:09 UTC

    Check the server error log to determine why it is returning the 500 (internal server error) to your client.

      Somehow not able to trouble shoot. Are the packages which are included sufficient or I should have JSON also included.when i Googled I came across some

        If the packages you include are/were insufficient, then you shouldn't get as far as running the test - perl should have blown up long before.

        A user level that continues to overstate my experience :-))
Re: Rest API testing with perl
by Anonymous Monk on May 11, 2014 at 21:12 UTC
    I can spot the a problem right now ... you cannot predefine the session-id. You must follow the protocol to obtain one from the host.
      I am still struck. I am changing the session id while passing it.

        Hmm, session-id is something you get, its not something you change ...

        Hello Mr. Lanlord, thanks for these keys to my new apartment ... I'll change these keys now ... my session-id keys that I changed won't open my apartment, whats wrong?