Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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; }

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 (Monsignor) 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?
[Corion]: (maybe I should write this up as a SoPW) - currently, the "most efficient" data structure I come up with is a single array which I scan for the first fitting one-shot. Not efficient but I don't expect more than five outstanding one-shots anyway
[choroba]: can't you create a meta-key corresponding to the disjunction of the events?
[robby_dobby]: Corion: Heh. This whole thing smells of Strategy Pattern or MVC pattern.
[Corion]: And performance linear to the number of registered one-shots doesn't feel that bad. Maybe I should collect statistics on how many callbacks are outstanding ;)
[Corion]: choroba: Yes, but the longer I thought about efficient hashes mapping the event type back to their callbacks, and how to keep them in sync, the more I thought that all that optimization might just not be worth it, even if it's horribly inelegant
[Lady_Aleena]: My biggest problem with hashes at the moment is one with 2,501 keys.
[choroba]: how many event types are there?
[Corion]: Also I found that I can't conveniently weaken an array slot, which also is inconvenient, as I want my one-shots to disappear if the caller discards them
[Corion]: choroba: Currently two or three that my program handles (WWW::Mechanize:: Chrome), but there might be more that become interesting
[Corion]: But I don't expect more than 100 to be active at the same time, so I'm not really sure if there is a not-too-fancy data structure that is maintained with few lines of code where the performance is better than the linear scan ;)

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-05-29 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?