in reply to HTTP Post read response , Post again

All I wanted to do is use HTTP1.1 Post x2 times as shown below

I believe you mean to do two requests on the same connection? Yet you do nothing to tell LWP to do so (assuming it's even capable of doing so).

So after webserver's response my connection and login becomes invalid.

Your login only lasts as long as the connection??? What kind of server is that! That defies the normal functioning of HTTP.

  • Comment on Re: HTTP Post read response , Post again

Replies are listed 'Best First'.
Re^2: HTTP Post read response , Post again
by gwadej (Chaplain) on Dec 18, 2008 at 21:56 UTC

    If it is indeed a login problem. The issue is that the OP is probably not keeping up with cookies.

    Since HTTP is a stateless protocol, the server has no concept of a login. The application may have a session concept which is normally tracked with cookies. This is why I suspect the problem is cookie related. As I recall, LWP::UserAgent has a feature for using HTTP::Cookies to track a cookie jar that handles this issue.

    G. Wade
      Looks like it. Any sample code to begin with? Will I be able to handle Java Session using IOR?

        It looks like you can either create an HTTP::Cookies object and pass it to the user agent object:

        require HTTP::Cookies; my $cookie_jar = HTTP::Cookies->new( file => 'cookies.txt, ); $ua->cookie_jar( $cookie_jar );

        or default to a temporary in-memory cookie jar with

        $ua->cookie_jar( {} );

        See HTTP::Cookies and LWP::UserAgent for more details.

        G. Wade
Re^2: HTTP Post read response , Post again
by perljunkie (Initiate) on Dec 19, 2008 at 15:19 UTC
    I believe you mean to do two requests on the same connection? Yet you do nothing to tell LWP to do so (assuming it's even capable of doing so). Yes. HTTP 1.1 Post; read response. If successful; post again with new request. But on the same connection. If you know TCP you will see in TCP header Source Port, Destination Port, Sequence Number, next sequence number, ack number. For two consutive posts TCP sequence number always starts from 1. Webserver is: thttpd.
    #!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request::Common; #Post 1 for login my $userAgent = LWP::UserAgent->new(agent => 'Perlprogram/0.1'); my $message = "UserID: Username, Password: passwordr"; my $response = $userAgent->request(POST 'http://someip:port/', Content_Type => 'application/text', Connection => 'Keep-alive', Content => $message); #print $response->error_as_HTML unless $response->is_success; #print $response->as_string; if ($response->is_success) { print $response->content; #post again if success my $userAgent2 = LWP::UserAgent->new(agent => 'Perlprogram/0.1'); my $message2 = "GetParam"; my $response2 = $userAgent2->request(POST 'http://someip:port/', Content_Type => 'application/text', Connection => 'Keep-alive', Content => $message2); print $response2->error_as_HTML unless $response2->is_success; print $response2->as_string; } else { print $response->status_line, "\n"; }
    I see in some new response my Keep-alive syntext was not proper. Let me modify and will post you result. Thanks for replies guys.....