[ic] HTTP POSTing to another server from IC

Grant listbox at email.com
Thu Aug 21 11:54:10 EDT 2003


> On Wed, 2003-08-20 at 23:46, Grant wrote:
> > I need to POST HTTP requests to another server from IC.  I've
> been all over
> > this thread (
> >
> http://www.icdevgroup.org/pipermail/interchange-users/2003-Februar
> y/031565.h
> > tml ) and an example I have of it being done in Perl and I can't seem to
> > figure out how to make it happen in IC after working on it for
> most of the
> > day.  What I need to do is pass certain headers and an XML request to a
> > certain URL.  Can anyone help?  Am I making sense?
> >
> > - Grant
>
> Try if these get you started. The posttourl tag should be able to handle
> regular http without ssl.
>
> ###############################
> Usertag posttourl Order url params
> Usertag posttourl Interpolate 1
> Usertag posttourl Routine <<EOR
*tag snipped*
> }
> EOR
> ####################################
>
> #####################################
> Usertag parsexml hasEndTag
> Usertag parsexml Interpolate 1
> Usertag parsexml Routine <<EOR
*tag snipped*
> }
> EOR
>
>
> ###################################
> Regards,
>
> Marc Brevoort

Thanks a lot for your help Marc.  I haven't delved into the XML parsing tag
yet, but I'm trying to get posttourl.tag set up and it looks good to me but
IC spits out an error after restarting with the tag in the UserTag folder.
The error looks like this:

Calling UI...UserTag 'posttourl' code is not a subroutine reference
In line 34 of the configuration file
'/trippystore/ic493/code/UserTag/posttourl.tag':

Here's the tag modified for my purposes:

Usertag posttourl Order url params apicall
Usertag posttourl Interpolate 1
Usertag posttourl Routine <<EOR
sub {
require HTTP::Request;
require HTTP::Headers;
require LWP::UserAgent; # SSL cabable if Crypt::SSLeay installed
        my $url=shift; my $params=shift;
        $ENV{'HTTPS_VERSION'} = '3';
        $ENV{'HTTPS_CERT_FILE'}='xxx.pem';
	$ENV{'HTTPS_KEY_FILE'}='xxx.key';

        my $page="";
        my $request=new HTTP::Request 'POST' => $url;
        $request->Content-Type('text/xml');
        $request->Content($params);
        $request->Content-Length(length($params));
        $request->X-API-COMPATIBILITY-LEVEL(305);
        $request->X-API-SESSION-CERTIFICATE' => 'staticinfo');
        $request->X-API-DEV-NAME' => 'staticinfo');
        $request->X-API-APP-NAME' => 'staticinfo');
        $request->X-API-CERT-NAME' => 'staticinfo');
        $request->X-API-CALL-NAME' => '$apicall');
        $request->X-API-SITEID' => '0');
        $request->X-API-DETAIL-LEVEL' => '0');

        my $ua=LWP::UserAgent->new;
        my $response = $ua->request($request);
        $page.=$response->as_string,"\n\n\n";
        $page.=$response->code,"\n";
        $page.=$response->message,"\n";
        return $page;
}
EOR

and here's the code I plan to call it with as well:

[perl]
        $url="https://the.url";
        $params="<?xml version='1.0' encoding='iso-8859-1'?>
   	<request>
   	<RequestUserId>userID</RequestUserId>
   	<RequestPassword>pword</RequestPassword>
   	<ErrorLevel>1</ErrorLevel>
   	<DetailLevel>0</DetailLevel>
   	<Verb>APICall</Verb>
   	</request>";
        $apicall="APICall";
        my $to_eval="[posttourl $url $params $apicall]";
        return $to_eval;
[/perl]

I really only know a little about Perl that I've picked up by playing with
IC.  There may be one or more glaring errors in the above.  Thanks!

- Grant



More information about the interchange-users mailing list