Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Rest API testing with perl

by madhurivepa (Novice)
on May 11, 2014 at 18:30 UTC ( #1085708=perlquestion: print w/ replies, xml ) Need Help??
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; }

Comment on Rest API testing with perl
Download Code
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 (Curate) 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?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-08-29 01:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls