Страница 1 из 1

Perl, как перевести скрипт из php в perl?

Добавлено: 2011-05-10 15:14:43
brainiac
Уважаемые гуру, помогите перенести скрипт из php в Perl .
Собсно на пхп то все пучком, мне нужно на перле это сделать, скока запросов и поисков не делал в гугл и яндых так и не воткнул :st: , как реализовать на перле.
Вот что на пхп:

Код: Выделить всё

#!/usr/local/php/bin/php
<?php
$text="Hello бойз энд гёрлс";
$smstext = iconv ('koi8-r', 'utf-8', $text);
$str = "<?xml version='1.0' encoding='UTF-8'?>
<data>
<login>my_login</login>
<password>here_password</password>
<action>send</action>
<text>".$smstext."</text>
<to number='7xxxxxxxxxx'></to>
</data>";
$url = "https://go-to-sms.com:7214/send.xml";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $str); // add POST fields
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
curl_close($ch);
header ("Content-type: text/plain");
//echo $result;
?>
На перле наваял примерно такое наскока соображалки хватило.:

Код: Выделить всё

#!/usr/bin/perl -w
use strict;
use LWP;
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new();
$ua->agent("PerlUA/0.1");
my $url = "https://go-to-sms.com:7214/send.xml";
my $request = POST $url;
my $document = $ua->request($request);
if ($document->is_success)
{
        print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        print "<data>\n";
        print "<login>Login</login>\n";
        print "<password>password</password>\n";
        print "<action>send</action>\n";
        print "<text>TEXT</text>\n";
        print "<to number='+7xxxxxxxxx'></to>\n";
        print "</data>\n";
}
exit(0);
он вроде как без ошибок отрабатывает, но ниче не посылает. Блин замаялся, народ мож поможет кто как на перле сделать правильно?

Re: Perl, как перевести скрипт из php в perl?

Добавлено: 2011-05-10 15:19:28
ProFTP

Код: Выделить всё

print $document->as_string;

Re: Perl, как перевести скрипт из php в perl?

Добавлено: 2011-05-10 15:53:56
brainiac
Сделал так:

Код: Выделить всё

#!/usr/bin/perl -w
use strict;
use LWP;
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new();
$ua->agent("PerlUA/0.1");
my $url = "https://go-to-sms.com:7214/send.xml";
my $request = POST $url;
my $document = $ua->request($request);
if ($document->is_success)
{
        print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        print "<data>\n";
        print "<login>Login</login>\n";
        print "<password>password</password>\n";
        print "<action>send</action>\n";
        print "<text>TEXT</text>\n";
        print "<to number='+7xxxxxxxxx'></to>\n";
        print "</data>\n";
}
print $document->as_string;
exit(0);
В ответ получаю

Код: Выделить всё

500 Can't connect to go-to-sms.com:7214 (certificate verify failed)
Content-Type: text/plain
Client-Date: Tue, 10 May 2011 12:42:00 GMT
Client-Warning: Internal response

Can't connect to go-to-sms.com:7214 (certificate verify failed)

LWP::Protocol::https::Socket: SSL connect attempt failed with unknown errorerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed at /usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm line 51.

Re: Perl, как перевести скрипт из php в perl?

Добавлено: 2011-05-11 17:34:43
thefree
модуль socket ssl стоит?

Re: Perl, как перевести скрипт из php в perl?

Добавлено: 2011-05-11 17:44:39
thefree
и вообще то что написано у вас бред (: если честно читайте инфу по модулю HTTP::Request::Common пишится всё в 2-3 строки

Re: Perl, как перевести скрипт из php в perl?

Добавлено: 2011-05-11 18:52:19
brainiac
Знаю что бред потому и спрашивал, знал бы - не просил.
Сделал все проще, просто передаю из перлового скрипта в пхпшный параметры и все работает на ок.

пээс
Если кто сделат скрипт на перле буду благодарен, хотя думаю и остальным он будет полезен.