[Edinburgh-pm] WWW::Curl::Easy
Alex Brelsfoard
alex.brelsfoard at gmail.com
Tue Sep 21 07:28:15 PDT 2010
Hi All,
Does anyone have any experience with WWW::Curl:Easy?
I'm needing to convert some code that currently uses HTTP::Request and
LWP::UserAgent into WWW::Curl::Easy code.
I've got most of it working, there just one case that is not.
I need to send content along with this particular query.
Here is what I need to convert to WWW::Mechanize:
---------------------- CODE ----------------------
my $req = new HTTP::Request POST => $url;
$req->content_type("text/xml");
$req->header("Authorization", "Basic ".$self->{'config'}->{'creds_64'});
$req->header("Cookie", $self->{'config'}{'seller_cookies'});
$req->header("FileFormat", "TabDelimited");
$req->header("BatchID", "Y");
$req->content($content);
my $response = $self->{'ua'}->request($req);
---------------------- /CODE ----------------------
That code works perfectly fine.
This is what I have so far for WWW::Curl::Easy:
---------------------- CODE ----------------------
my @headers = ('Content-Type: text/xml',
'Authorization: Basic
'.$self->{'config'}->{$self->{'locale'}}->{'seller_creds_64'},
'Cookie: '.$self->{'config'}{'seller_cookies'},
'FileFormat: TabDelimited',
'BatchID: Y'
);
$self->{'curl'} = new WWW::Curl::Easy;
$self->{'curl'}->setopt(CURLOPT_HEADER,0);
$self->{'curl'}->setopt(CURLOPT_HTTPHEADER,\@headers);
$self->{'curl'}->setopt(CURLOPT_POST, 1);
$self->{'curl'}->setopt(CURLOPT_POSTFIELDS, $content);
$self->{'curl'}->setopt(CURLOPT_URL, $url);
open (my $response_handle, ">", \$response_body);
$self->{'curl'}->setopt(CURLOPT_WRITEDATA,$response_handle);
my $retcode = $self->{'curl'}->perform;
---------------------- /CODE ----------------------
But I'm getting a message back saying that it's not seeing the added
$content properly/at all.
I'm very new to WWW::Curl::Easy and so could use any help.
As I said before, I have standard page curls working perfectly fine,
including ones where I send the extra header information.
It's just when I try to send extra $content.
I think this content might need to be sent as an attachment somehow....
Thanks in advance to anyone who can help me out.
--Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/edinburgh-pm/attachments/20100921/044b6969/attachment-0001.html>
More information about the Edinburgh-pm
mailing list