[ic] posttourl.tag
Grant
listbox at email.com
Fri Aug 29 20:01:28 EDT 2003
> At 03:01 PM 8/29/2003 -0700, you wrote:
> >*snip*
> > > Both HTTP::Headers and HTTP::Request have very good manual pages, and
> > > the changes to your code will be very simple.
> >*snip*
> >
> >After checking out the man pages on HTTP::Headers, I changed the "-"
> >characters in my headers to "_" and after another minor change,
> IC restarts
> >with the tag without any errors. I feel like I'm close to a successful
> >POST. I set up a test page to call the posttourl.tag and got a
> 500 error.
> >I noticed the following in my error.log:
> >
> >
> >[29/August/2003:10:18:24 -0700] path/test.html Runtime error:
> Can't locate
> >object method "X_API_COMPATIBILITY_LEVEL" via package "HTTP::Headers" at
> >/usr/lib/perl5/site_perl/5.6.0/HTTP/Message.pm line 189.
> >
> >
> >Can anyone interpret that error and point me in the right
> direction as far
> >as fixing it? I'm calling posttourl.tag with the following code:
> >
> >
> >[perl]
> > # params are passed to posttourl via cgi to allow
> > # fixed string with variable values
> > my $page="";
> > $CGI->{url}="https://the.url";
> > $CGI->{params}="<?xml version='1.0'
> > encoding='iso-8859-1'?><request>a bunch
> >of XML</request>";
> > $CGI->{apicall}="thecall";
> > $page.="Connecting to ".$CGI->{url}
> > ."?".$CGI->{params}."<br>\n";
> >
> > $CGI->{C016}="";
> > return $page;
> >[/perl]
> >[seti postonly]
> >[posttourl url="[cgi url]" params="[cgi params]" apicall="[cgi apicall]"]
> >[/seti]
> >
> >
> >and here's the posttourl.tag:
> >
> >
> >Usertag posttourl Order url params apicall
> >Usertag posttourl Routine <<EOR
> >use HTTP::Request;
> >use HTTP::Headers;
> >use LWP::UserAgent;
> >sub {
> > my ($url,$params,$apicall) = @_;
> >
> > local($ENV{'HTTPS_VERSION'}) = '3';
> > local($ENV{'HTTPS_CERT_FILE'}) = 'xxx.pem';
> > local($ENV{'HTTPS_KEY_FILE'}) = 'xxx.key';
> >
> > my $request = new HTTP::Request('POST' => $url);
> > $request->content_type('application/x-www-form-urlencoded');
> > $request->content($params);
> > $request->content_length(length($params));
> > $request->X_API_COMPATIBILITY_LEVEL(305);
> > $request->X_API_SESSION_CERTIFICATE('sensitive');
> > $request->X_API_DEV_NAME('sensitive');
> > $request->X_API_APP_NAME('sensitive');
> > $request->X_API_CERT_NAME('sensitive');
> > $request->X_API_CALL_NAME($apicall);
> > $request->X_API_SITEID(0);
> > $request->X_API_DETAIL_LEVEL(0);
> >
> > my $ua = new LWP::UserAgent;
> > my $response = $ua->request($request);
> >
> > my $page = $response->as_string() . "\n\n\n";
> > $page .= $response->code() . "\n";
> > $page .= $response->message() . "\n";
> >
> > return $page;
> >}
> >EOR
> >
> >
> >- Grant
>
> From perldoc HTTP::Request -
>
> $r = HTTP::Request->new($method, $uri, $header, $content)
> Constructs a new "HTTP::Request" object describing a
> request on the object "$uri" using method "$method".
> The "$uri" argument can be either a string, or a ref-
> erence to a "URI" object. The optional $header argu-
> ment should be a reference to an "HTTP::Headers"
> object. The optional $content argument should be a
> string.
>
>
> From perldoc HTTP::Headers -
>
> $h = HTTP::Headers->new
> Constructs a new "HTTP::Headers" object. You might
> pass some initial attribute-value pairs as parameters
> to the constructor. E.g.:
>
> $h = HTTP::Headers->new(
> Date => 'Thu, 03 Feb 1994 00:00:00 GMT',
> Content_Type => 'text/html; version=3.2',
> Content_Base => 'http://www.perl.org/');
>
>
>
> ...so in your case I think you would want to do something like:
>
> my $header = HTTP::Headers->new(
> X_API_COMPATIBILITY_LEVEL => '305',
> X_API_SESSION_CERTIFICATE => 'sensitive',
> [etc...]
> );
>
> ...then pass $header to your http request per the docs.
>
> - Ed L.
After a lot of fiddling I added everything into the usertag so nothing
needed to be passed into it. I'm now calling the tag with [posttourl] and I
changed the first line of the tag to:
Usertag posttourl Order
I think the response is being saved to a variable. How can I have the
variable's contents dumped to the screen?
- Grant
More information about the interchange-users
mailing list