Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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 fail 500 at 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/'); 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 (Canon) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1085708]
Approved by davies
and all is quiet...

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

    Results (126 votes). Check out past polls.