473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Any perl folks can help with some translation?

I've got a 2rd party API written in perl. We want to use it by converting
to a c# .net assembly. Essentially it does HTTP posts to a web page to
send/receive data. I've never done perl, and am hoping someone can help
with conversion, particularly around the setup of the $UA variable and doing
the post.

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Status;
use HTTP::Cookies;
use HTTP::Request::Common qw(POST);
use strict;

#Setup package Variables
my ($COOKIE_JAR, $UA, $WEBBASE, $DIR, $DEBUG);
my ($Messages, $Tid, $Result, $Filename) = ("", "", "", "");

#Setup package Constants
my ($RESPONSE, $TMPFILE) = ("response.tmp", "temp.tmp");

use vars qw ($NOT_IMPLEMENTED $ERROR $VALID $SUCCESS);
($NOT_IMPLEMENTED, $ERROR, $VALID, $SUCCESS) = (-2, -1, 0, 1);
1;
sub init
{
$WEBBASE = "https://localhost/test";
my ($timeout);
($WEBBASE, $timeout, $DIR, $DEBUG) = @_;
my ($cookiefile) = "cookies.txt";
if (-d $DIR)
{
$COOKIE_JAR = HTTP::Cookies->new(File =$DIR . $cookiefile,
AutoSave =1,
ignore_discard =1);
$UA = new LWP::UserAgent;
$UA->agent("TestPerl 1.0");
$UA->from("TestAPI");
$UA->timeout($timeout);
$UA->cookie_jar($COOKIE_JAR);
$COOKIE_JAR->save();
return $SUCCESS;
}
else
{
$Messages = "$DIR is not a valid directory";
return $ERROR;
}
}

sub login
{
my ($uid, $pw) = @_;
my $request = POST $WEBBASE, [ 'username' =$uid,
'password' =$pw,
'ExternalAction' ='AsignOn'];
my $retVal = processRequest($request);
if ($retVal == $SUCCESS)
{#valid response
if ($Result ne "SUCCESS")
{
$retVal = $VALID;
}
}
else
{
$retVal = $ERROR;
}
return $retVal;
}
Aug 2 '06 #1
3 1362
Jeremy,

I don't know PERL, but it looks to me like you would want to use the
HttpWebRequest and HttpWebResponse classes in order to perform this
request/response. It shouldn't be too hard to configure the properties from
the values in this script.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeremy Chapman" <please@Idontlikespamwrote in message
news:O0*************@TK2MSFTNGP03.phx.gbl...
I've got a 2rd party API written in perl. We want to use it by converting
to a c# .net assembly. Essentially it does HTTP posts to a web page to
send/receive data. I've never done perl, and am hoping someone can help
with conversion, particularly around the setup of the $UA variable and
doing the post.

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Status;
use HTTP::Cookies;
use HTTP::Request::Common qw(POST);
use strict;

#Setup package Variables
my ($COOKIE_JAR, $UA, $WEBBASE, $DIR, $DEBUG);
my ($Messages, $Tid, $Result, $Filename) = ("", "", "", "");

#Setup package Constants
my ($RESPONSE, $TMPFILE) = ("response.tmp", "temp.tmp");

use vars qw ($NOT_IMPLEMENTED $ERROR $VALID $SUCCESS);
($NOT_IMPLEMENTED, $ERROR, $VALID, $SUCCESS) = (-2, -1, 0, 1);
1;
sub init
{
$WEBBASE = "https://localhost/test";
my ($timeout);
($WEBBASE, $timeout, $DIR, $DEBUG) = @_;
my ($cookiefile) = "cookies.txt";
if (-d $DIR)
{
$COOKIE_JAR = HTTP::Cookies->new(File =$DIR . $cookiefile,
AutoSave =1,
ignore_discard =1);
$UA = new LWP::UserAgent;
$UA->agent("TestPerl 1.0");
$UA->from("TestAPI");
$UA->timeout($timeout);
$UA->cookie_jar($COOKIE_JAR);
$COOKIE_JAR->save();
return $SUCCESS;
}
else
{
$Messages = "$DIR is not a valid directory";
return $ERROR;
}
}

sub login
{
my ($uid, $pw) = @_;
my $request = POST $WEBBASE, [ 'username' =$uid,
'password' =$pw,
'ExternalAction' ='AsignOn'];
my $retVal = processRequest($request);
if ($retVal == $SUCCESS)
{#valid response
if ($Result ne "SUCCESS")
{
$retVal = $VALID;
}
}
else
{
$retVal = $ERROR;
}
return $retVal;
}

Aug 2 '06 #2
I've found the HttpWebRequest and response classes, but I'm not sure what
the POST $WEBBASE, [ 'username' =$uid,'password' =>
$pw,'ExternalAction' ='AsignOn']; statement does to the request. Also I
don't know what the $UA->from("TestAPI"); line sets either.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:uL**************@TK2MSFTNGP04.phx.gbl...
Jeremy,

I don't know PERL, but it looks to me like you would want to use the
HttpWebRequest and HttpWebResponse classes in order to perform this
request/response. It shouldn't be too hard to configure the properties
from the values in this script.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeremy Chapman" <please@Idontlikespamwrote in message
news:O0*************@TK2MSFTNGP03.phx.gbl...
>I've got a 2rd party API written in perl. We want to use it by
converting to a c# .net assembly. Essentially it does HTTP posts to a
web page to send/receive data. I've never done perl, and am hoping
someone can help with conversion, particularly around the setup of the
$UA variable and doing the post.

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Status;
use HTTP::Cookies;
use HTTP::Request::Common qw(POST);
use strict;

#Setup package Variables
my ($COOKIE_JAR, $UA, $WEBBASE, $DIR, $DEBUG);
my ($Messages, $Tid, $Result, $Filename) = ("", "", "", "");

#Setup package Constants
my ($RESPONSE, $TMPFILE) = ("response.tmp", "temp.tmp");

use vars qw ($NOT_IMPLEMENTED $ERROR $VALID $SUCCESS);
($NOT_IMPLEMENTED, $ERROR, $VALID, $SUCCESS) = (-2, -1, 0, 1);
1;
sub init
{
$WEBBASE = "https://localhost/test";
my ($timeout);
($WEBBASE, $timeout, $DIR, $DEBUG) = @_;
my ($cookiefile) = "cookies.txt";
if (-d $DIR)
{
$COOKIE_JAR = HTTP::Cookies->new(File =$DIR . $cookiefile,
AutoSave =1,
ignore_discard =1);
$UA = new LWP::UserAgent;
$UA->agent("TestPerl 1.0");
$UA->from("TestAPI");
$UA->timeout($timeout);
$UA->cookie_jar($COOKIE_JAR);
$COOKIE_JAR->save();
return $SUCCESS;
}
else
{
$Messages = "$DIR is not a valid directory";
return $ERROR;
}
}

sub login
{
my ($uid, $pw) = @_;
my $request = POST $WEBBASE, [ 'username' =$uid,
'password' =$pw,
'ExternalAction' ='AsignOn'];
my $retVal = processRequest($request);
if ($retVal == $SUCCESS)
{#valid response
if ($Result ne "SUCCESS")
{
$retVal = $VALID;
}
}
else
{
$retVal = $ERROR;
}
return $retVal;
}


Aug 2 '06 #3
Jeremy,

If I had to guess, username and password would be set on the Credentials
property of the HttpWebRequest.

The $UA->from("TestAPI") call sets the From header, which you can set
through the Headers collection.

I was able to figure that out from the following document on Goggle:

http://kobesearch.cpan.org/htdocs/li...UserAgent.html

I basically searched for "LWP::UserAgent".

As for the external action, I'm not so sure, but you should be able to
find some documentation for the libraries that script imports and figure out
what it does.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Jeremy Chapman" <please@Idontlikespamwrote in message
news:uJ**************@TK2MSFTNGP04.phx.gbl...
I've found the HttpWebRequest and response classes, but I'm not sure what
the POST $WEBBASE, [ 'username' =$uid,'password' =>
$pw,'ExternalAction' ='AsignOn']; statement does to the request. Also I
don't know what the $UA->from("TestAPI"); line sets either.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:uL**************@TK2MSFTNGP04.phx.gbl...
>Jeremy,

I don't know PERL, but it looks to me like you would want to use the
HttpWebRequest and HttpWebResponse classes in order to perform this
request/response. It shouldn't be too hard to configure the properties
from the values in this script.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeremy Chapman" <please@Idontlikespamwrote in message
news:O0*************@TK2MSFTNGP03.phx.gbl...
>>I've got a 2rd party API written in perl. We want to use it by
converting to a c# .net assembly. Essentially it does HTTP posts to a
web page to send/receive data. I've never done perl, and am hoping
someone can help with conversion, particularly around the setup of the
$UA variable and doing the post.

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Status;
use HTTP::Cookies;
use HTTP::Request::Common qw(POST);
use strict;

#Setup package Variables
my ($COOKIE_JAR, $UA, $WEBBASE, $DIR, $DEBUG);
my ($Messages, $Tid, $Result, $Filename) = ("", "", "", "");

#Setup package Constants
my ($RESPONSE, $TMPFILE) = ("response.tmp", "temp.tmp");

use vars qw ($NOT_IMPLEMENTED $ERROR $VALID $SUCCESS);
($NOT_IMPLEMENTED, $ERROR, $VALID, $SUCCESS) = (-2, -1, 0, 1);
1;
sub init
{
$WEBBASE = "https://localhost/test";
my ($timeout);
($WEBBASE, $timeout, $DIR, $DEBUG) = @_;
my ($cookiefile) = "cookies.txt";
if (-d $DIR)
{
$COOKIE_JAR = HTTP::Cookies->new(File =$DIR . $cookiefile,
AutoSave =1,
ignore_discard =1);
$UA = new LWP::UserAgent;
$UA->agent("TestPerl 1.0");
$UA->from("TestAPI");
$UA->timeout($timeout);
$UA->cookie_jar($COOKIE_JAR);
$COOKIE_JAR->save();
return $SUCCESS;
}
else
{
$Messages = "$DIR is not a valid directory";
return $ERROR;
}
}

sub login
{
my ($uid, $pw) = @_;
my $request = POST $WEBBASE, [ 'username' =$uid,
'password' =$pw,
'ExternalAction' ='AsignOn'];
my $retVal = processRequest($request);
if ($retVal == $SUCCESS)
{#valid response
if ($Result ne "SUCCESS")
{
$retVal = $VALID;
}
}
else
{
$retVal = $ERROR;
}
return $retVal;
}



Aug 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
by: Market Mutant | last post by:
I just wonder job selections, job openings and salary level of PHP programer or Perl programmer comparing to Java programmers. Is Java programmer's salary has a minimal of 60K in US? Are there...
3
by: Helmut Jarausch | last post by:
Hi, having been a Perl fan for years I have nearly converted to Python. Still, there are LOTS and very good modules written in Perl. Is there a tool to lesson the burdon of translation of Perl...
42
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time....
6
by: Stephen Ferg | last post by:
I need to translate some Perl scripts into Python. When I went looking for a tool that would help automate the translation, I was rather surprised that I couldn't find anything. BridgeKeeper,...
31
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is...
41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
2
by: Paul Porcelli | last post by:
Hi folks, I have a perl one-liner embedded in a ksh script. perl -pi.bak -e "s/val/otherval/" inputfile I'd like to check the return code to know if the substitution was successful. If I...
2
by: Iain | last post by:
Folks, I'm having a problem with charset encodings that I desparately need some help with. I don't even pretend to know the basics about charsets, so please forgive my ignorance. I am...
1
by: Darshan | last post by:
I have n number of C files which have French + English comments in them. Now i have written a code which greps all the comments. What is the best way to get the comments translated using a online...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.