Я хочу использовать WWW::Curl
вместо LWP::UserAgent
для отправки запроса на публикацию.Ниже приведен код, использующий LWP::UserAgent
, который работает нормально.
my $agent = LWP::UserAgent->new(agent => 'perl post');
push @{ $agent->requests_redirectable }, 'POST';
my $header = HTTP::Headers->new;
$header->header('Content-Type' => "text/xml; charset=UTF-8");
$header->content_encoding('gzip');
utf8::encode( my $utf8_content = $args{content} );
sinfo $utf8_content;
$error->description($utf8_content);
$error->log;
my $request = HTTP::Request->new(POST => $args{url}, $header, $utf8_content);
my $response = $agent->request($request);
Мне нужно переписать этот код, используя WWW :: Curl, поскольку Curl работает быстрее, чем LWP.Я пробовал приведенный ниже код, но он возвращает мне код 35 в качестве ответа, что означает, что запрос недействителен.
my $curl = WWW::Curl::Easy->new();
$curl->setopt(WWW::Curl::Easy::CURLOPT_HEADER,1);
$curl->setopt(WWW::Curl::Easy::CURLOPT_URL,$self->uri());
$curl->setopt(WWW::Curl::Easy::CURLOPT_POST, 1);
$curl->setopt(WWW::Curl::Easy::CURLOPT_POSTFIELDS, $utf8_content);
my $response;
$curl->setopt(WWW::Curl::Easy::CURLOPT_WRITEDATA,\$response);
my $retcode = $curl->perform();
Данные, которые я передаю в запросе post ($ utf8_content), представляют собой строку xmlпример xml:
<Request>
<Source>
<RequestorID Password="PASS" Client="Client" EMailAddress="email@address.com"/>
<RequestorPreferences Language="en">
<RequestMode>SYNCHRONOUS</RequestMode>
</RequestorPreferences>
</Source>
<RequestDetails>
<SearchRequest>
<ItemDestination DestinationType="area" DestinationCode="XYZ"/>
</ItemDestination>
</SearchRequest>
</RequestDetails>
</Request>
Более того, ответом будет также строка XML, которую можно получить из $ response;