Perl 到 PHP 翻译

发布于 2024-09-14 06:40:23 字数 458 浏览 2 评论 0原文

您可以将此 Perl 代码转换为 PHP 代码吗?

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5');
$ua -> timeout(0.5);
my $req = POST 'http://forums.shooshtime.com/',
[ vb_login_username => 'mehdi' , vb_login_password => '***' , go => 'submit'];
my $content = $ua->request($req);

提前致谢 。

may you convert this Perl code to PHP code ?

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5');
$ua -> timeout(0.5);
my $req = POST 'http://forums.shooshtime.com/',
[ vb_login_username => 'mehdi' , vb_login_password => '***' , go => 'submit'];
my $content = $ua->request($req);

Thanks in Advance .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深爱成瘾 2024-09-21 06:40:23

干得好。转换为 PHP 的完整代码:

<?php
//set URL
$url = 'http://forums.shooshtime.com/';

//set POST variables
$fields = array(
    'vb_login_username' => 'mehdi',
    'vb_login_password' => '***' ,
    'go' => 'submit'
                );

// set user agent
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5';

//open connection
$ch = curl_init();

//set the url, POST data, UserAgent, Timeout, etc.
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 500); //time out of 0.5 seconds.

//execute post
$content = curl_exec($ch);

//close connection
curl_close($ch);
?>

Here you go. Complete code converted to PHP:

<?php
//set URL
$url = 'http://forums.shooshtime.com/';

//set POST variables
$fields = array(
    'vb_login_username' => 'mehdi',
    'vb_login_password' => '***' ,
    'go' => 'submit'
                );

// set user agent
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5';

//open connection
$ch = curl_init();

//set the url, POST data, UserAgent, Timeout, etc.
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 500); //time out of 0.5 seconds.

//execute post
$content = curl_exec($ch);

//close connection
curl_close($ch);
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文