You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by John Soto <js...@jefco.com> on 2000/10/31 20:54:39 UTC

Problem reading content...


Having problem reading POSTed content.... Am trying to write handler which will
pass content onto MQ. Currently, I have the content as text\plain and not
url-encoded.
Here's my POSTing snippet...

#! /usr/bin/perl -w

use LWP::UserAgent;
use HTTP::Request;

$ua = LWP::UserAgent->new();
$ua->agent("$0/1.0");
$url = "http://tssdatadev.jc.jefco.com/wilco/PutXml/asynch";

$req = new HTTP::Request 'POST',$url;

$req->content_type('text/plain');
#$req->content_type('multipart/form-data');

$req->content_length(33);
$req->content("easter bunny is coming to town...");
$resp = $ua->request($req);
print $resp->as_string;

######################################################

Here's a snippet of the handler. I'm using read() to get the content... I
receive the content-length with no problem, but am unable to read the content.



package WILCO::PutXml;

#use strict "refs";

use Apache::Constants qw(:common);
use Apache::Registry;
use MQSeries;
use CGI;
use Carp;

do 'Constants.pl';
use lib '/apps/lib/perl';
require 'jefco.pm';

sub handler {

  my $r = shift;


# Parse out how I'm being called
  my($method);
  ($method=$r->uri)=~s!^.*/wilco/PutXml/(\w+)!$1!;
  $method =~ s/\?.*//;

# Get my arguments
#  my($http) = new CGI( $r->args || $r->content );
#  my %params = ($r->content, $r->args);


# Autoflush the output buffer
  $| = 1;
  open(XML,">/tmp/xml.log") || die "Cannot create log file: $!\n";


  $r->content_type('text/html');
  $r->header_out('pragma','no-cache');
  $r->send_http_header;


  $r->warn ("<!-- --------------------------- -->\n");
  $r->warn ("<!-- START PROGRAM - PutXml -->\n");
  $r->warn  ("<!-- Method = $method       -->\n");

############################################################################
# setup defaults, and envionment vairiables
############################################################################

  $ENV{MQSERVER} = $MQSERVER;

  my $PutQ = 'QL.WILCO.IN';
  my $GetQ1 = 'QL.WILCO.SYNC.OUT';
  my $GetQ2 = 'QL.WILCO.ASYNC.OUT';

  my $Msg;
  $r->read($Msg, $r->header_in('Content-length'));

  $r->warn ("<!-- ------------------------- -->");
  $r->warn ("<!-- ENVIRONMENT VARIABLES : -->");
  $r->warn ("<!-- mqserver     = $MQSERVER -->");
  $r->warn ("<!-- Queue Manager= $QM -->");
  if (!($Msg)){$r->warn ("<!-- Msg = $Msg -->");}

I get nothing in $Msg... What am I missing here???

Thanks in advance!



--------------------------------------------------------------
Jefferies archives and reviews outgoing and incoming e-mail.  Such may be 
produced at the request of regulators. Sender accepts no liability for 
any errors or omissions arising as a result of  transmission. Use by other than 
intended recipients is prohibited. This is neither an offer nor a 
solicitation of an offer to buy or sell securities. Opinions or estimates 
constitute our best judgment at this time and are subject to change without 
notice. Information upon which this material is based was obtained from 
sources believed to be reliable but has not been verified. Additional 
information is available upon request. Jefferies its affiliates and 
respective directors officers and employees may buy or sell 
securities mentioned as agent or principal. This is for use by 
professional or institutional investors only. No investments or 
services mentioned or described are available to "private 
customers" as defined by the SFA or to anyone in Canada not a "Designated 
Institution". 

Re: Problem reading content...

Posted by Thomas von Elling Skifter Eibner <th...@io.stderr.net>.
On Tue, Oct 31, 2000 at 02:54:39PM -0500, John Soto wrote:
> 
> Having problem reading POSTed content.... Am trying to write handler which will
> pass content onto MQ. Currently, I have the content as text\plain and not
> url-encoded.
> Here's my POSTing snippet...
> 
> #! /usr/bin/perl -w
> 
> use LWP::UserAgent;
> use HTTP::Request;
> 
> $ua = LWP::UserAgent->new();
> $ua->agent("$0/1.0");
> $url = "http://tssdatadev.jc.jefco.com/wilco/PutXml/asynch";
> 
> $req = new HTTP::Request 'POST',$url;
> 
> $req->content_type('text/plain');
> #$req->content_type('multipart/form-data');
> 
> $req->content_length(33);
> $req->content("easter bunny is coming to town...");
> $resp = $ua->request($req);
> print $resp->as_string;

Are you sure you can POST with a content-type of text/plain? I made a little script for some automatic form submitting where I did this (fitted in for your needs):

#!/usr/bin/perl -w

use strict;
use LWP::UserAgent;
use HTTP::Request;
use URI::Escape;

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

my $req = new HTTP::Request(POST => 'http://tssdatadev.jc.jefco.com/wilco/PutXml/asynch');
$req->content_type('application/x-www-form-urlencoded');
$req->content(uri_escape("easter bunny is coming to town...");
my $resp = $ua->request($req);
if ($res->is_success) {
    print $req->as_string;
} else {
    print "Bad luck this time\n";
}

__END__

Try with this snippet and see how your POST goes..

--
Thomas Eibner


> Here's a snippet of the handler. I'm using read() to get the content... I
> receive the content-length with no problem, but am unable to read the content.
> 
> 
> 
> package WILCO::PutXml;
> 
> #use strict "refs";
> 
> use Apache::Constants qw(:common);
> use Apache::Registry;
> use MQSeries;
> use CGI;
> use Carp;
> 
> do 'Constants.pl';
> use lib '/apps/lib/perl';
> require 'jefco.pm';
> 
> sub handler {
> 
>   my $r = shift;
> 
> 
> # Parse out how I'm being called
>   my($method);
>   ($method=$r->uri)=~s!^.*/wilco/PutXml/(\w+)!$1!;
>   $method =~ s/\?.*//;
> 
> # Get my arguments
> #  my($http) = new CGI( $r->args || $r->content );
> #  my %params = ($r->content, $r->args);
> 
> 
> # Autoflush the output buffer
>   $| = 1;
>   open(XML,">/tmp/xml.log") || die "Cannot create log file: $!\n";
> 
> 
>   $r->content_type('text/html');
>   $r->header_out('pragma','no-cache');
>   $r->send_http_header;
> 
> 
>   $r->warn ("<!-- --------------------------- -->\n");
>   $r->warn ("<!-- START PROGRAM - PutXml -->\n");
>   $r->warn  ("<!-- Method = $method       -->\n");
> 
> ############################################################################
> # setup defaults, and envionment vairiables
> ############################################################################
> 
>   $ENV{MQSERVER} = $MQSERVER;
> 
>   my $PutQ = 'QL.WILCO.IN';
>   my $GetQ1 = 'QL.WILCO.SYNC.OUT';
>   my $GetQ2 = 'QL.WILCO.ASYNC.OUT';
> 
>   my $Msg;
>   $r->read($Msg, $r->header_in('Content-length'));
> 
>   $r->warn ("<!-- ------------------------- -->");
>   $r->warn ("<!-- ENVIRONMENT VARIABLES : -->");
>   $r->warn ("<!-- mqserver     = $MQSERVER -->");
>   $r->warn ("<!-- Queue Manager= $QM -->");
>   if (!($Msg)){$r->warn ("<!-- Msg = $Msg -->");}
> 
> I get nothing in $Msg... What am I missing here???
> 
> Thanks in advance!