473,569 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_IMPLEMENT ED $ERROR $VALID $SUCCESS);
($NOT_IMPLEMENT ED, $ERROR, $VALID, $SUCCESS) = (-2, -1, 0, 1);
1;
sub init
{
$WEBBASE = "https://localhost/test";
my ($timeout);
($WEBBASE, $timeout, $DIR, $DEBUG) = @_;
my ($cookiefile) = "cookies.tx t";
if (-d $DIR)
{
$COOKIE_JAR = HTTP::Cookies->new(File =$DIR . $cookiefile,
AutoSave =1,
ignore_discard =1);
$UA = new LWP::UserAgent;
$UA->agent("TestPer l 1.0");
$UA->from("TestAPI" );
$UA->timeout($timeo ut);
$UA->cookie_jar($CO OKIE_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 1371
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.co m

"Jeremy Chapman" <please@Idontli kespamwrote in message
news:O0******** *****@TK2MSFTNG P03.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_IMPLEMENT ED $ERROR $VALID $SUCCESS);
($NOT_IMPLEMENT ED, $ERROR, $VALID, $SUCCESS) = (-2, -1, 0, 1);
1;
sub init
{
$WEBBASE = "https://localhost/test";
my ($timeout);
($WEBBASE, $timeout, $DIR, $DEBUG) = @_;
my ($cookiefile) = "cookies.tx t";
if (-d $DIR)
{
$COOKIE_JAR = HTTP::Cookies->new(File =$DIR . $cookiefile,
AutoSave =1,
ignore_discard =1);
$UA = new LWP::UserAgent;
$UA->agent("TestPer l 1.0");
$UA->from("TestAPI" );
$UA->timeout($timeo ut);
$UA->cookie_jar($CO OKIE_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,'ExternalAc tion' ='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.c omwrote in
message news:uL******** ******@TK2MSFTN GP04.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.co m

"Jeremy Chapman" <please@Idontli kespamwrote in message
news:O0******** *****@TK2MSFTNG P03.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_IMPLEMENT ED $ERROR $VALID $SUCCESS);
($NOT_IMPLEMEN TED, $ERROR, $VALID, $SUCCESS) = (-2, -1, 0, 1);
1;
sub init
{
$WEBBASE = "https://localhost/test";
my ($timeout);
($WEBBASE, $timeout, $DIR, $DEBUG) = @_;
my ($cookiefile) = "cookies.tx t";
if (-d $DIR)
{
$COOKIE_JAR = HTTP::Cookies->new(File =$DIR . $cookiefile,
AutoSave =1,
ignore_discard =1);
$UA = new LWP::UserAgent;
$UA->agent("TestPer l 1.0");
$UA->from("TestAPI" );
$UA->timeout($timeo ut);
$UA->cookie_jar($CO OKIE_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.co m
"Jeremy Chapman" <please@Idontli kespamwrote in message
news:uJ******** ******@TK2MSFTN GP04.phx.gbl...
I've found the HttpWebRequest and response classes, but I'm not sure what
the POST $WEBBASE, [ 'username' =$uid,'password ' =>
$pw,'ExternalAc tion' ='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.c omwrote
in message news:uL******** ******@TK2MSFTN GP04.phx.gbl...
>Jeremy,

I don't know PERL, but it looks to me like you would want to use the
HttpWebReque st 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.co m

"Jeremy Chapman" <please@Idontli kespamwrote in message
news:O0******* ******@TK2MSFTN GP03.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_IMPLEMENT ED $ERROR $VALID $SUCCESS);
($NOT_IMPLEME NTED, $ERROR, $VALID, $SUCCESS) = (-2, -1, 0, 1);
1;
sub init
{
$WEBBASE = "https://localhost/test";
my ($timeout);
($WEBBASE, $timeout, $DIR, $DEBUG) = @_;
my ($cookiefile) = "cookies.tx t";
if (-d $DIR)
{
$COOKIE_JAR = HTTP::Cookies->new(File =$DIR . $cookiefile,
AutoSave =1,
ignore_discard =1);
$UA = new LWP::UserAgent;
$UA->agent("TestPer l 1.0");
$UA->from("TestAPI" );
$UA->timeout($timeo ut);
$UA->cookie_jar($CO OKIE_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
16827
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 many PHP jobs?
3
2191
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 to Python? I am completely aware of the fact that a fully automatic translation to readable Python source is hard if not impossible. But such a tool...
42
4045
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. I'm not interested on which language is better in *general*, just for my purpose. My area of research is in CAD algorithms, and I'm sensing the...
6
3762
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, the only real candidate that I could find, is no longer available. There are of course general-purpose parsing packages, but I'm looking for...
31
4743
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 great for pattern matching, text processing, and automated testing. Our company is really fixated on risk managnemt and the only way I can do enough...
41
3508
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 pairs, each pair indicates the sameness of the two indexes. Returns a partitioned list of same indexes.
2
7453
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 type: # perl -pi.bak -e "s/val/otherval/" inputfile
2
2380
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 transforming XML source into XHTML using an encoding of iso-8859-1 and when I browse (using Mozilla 1.x) I see strange, accented 'A' characters preceeding...
1
1552
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 translator (like bablefish or google ...) and write all the translated texts back to the respective C files. Any pointers over the solution in...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.