Hello,

I have a question on how to use the PoCo::C:H module.

I am trying to connect to a site that requires that you auth, and I have previously 
used
the basic_authorization method to do this. Also, I am a bit confused as to posting 
things
to a CGI form. Here is how I would do it without using POE:

                my $ua = new LWP::UserAgent;
                $ua->agent("Mozilla/4.7");

                my $request = HTTP::Request->new(POST => $url[$i]);
                $request->content_type('application/x-www-form-urlencoded');
                $request->authorization_basic($logins[$i],$passwords[$i]);
                $request->content("$args[$i]");

                my $response = $ua->request($request);
                if ($response->is_success) {


        etc etc..

Using POE, I am trying to do it this way:

sub create_a_child {
  my($u_id,$site,$parts)=@_;    

  my $cookie_jar = HTTP::Cookies->new;

  POE::Component::Client::HTTP->spawn(
                                      Agent     => 'Mozilla/4.9',
                                      Alias     => 'ua',
                                      CookieJar => $cookie_jar,
                                      #Timeout  => '100',
                                     );
  POE::Session->create
    ( inline_states =>
      { _start  => \&child_start,
        _stop   => \&child_stop,
        got_response => \&client_got_response,
      },
      args => [ $u_id, $site, $parts ],
    );
}


child_start excerpt:

  $kernel->post( ua => request => got_response => 
                 POST "$search_url"
               );

and the got_response function:

  my($heap, $kernel, $request_packet, $request_response) = @_[HEAP, KERNEL, ARG0, 
ARG1];
  my $http_request = $request_packet->[0];
  my $http_response = $request_response->[0];

  $http_request->content_type('application/x-www-form-urlencoded');

    $http_request->authorization_basic($site_info{login},$site_info{passwd});
    $http_request->content("$site_info{args}=$fmt_string");
    
#    if ($http_response->is_success) {
    if ($http_response->code == 200) {

This method does not seem to work. The example you have given in the PoCo::Client::HTTP
distribution shows a different way of posting stuff to CGI forms, and has no mention
of how you do authorization.  Does anyone care to enlighten me as to what I am doing
wrong or overlooking? 

I am a bit confused.

thanks,
MikeF

Reply via email to