【问题标题】:Perl to Php Translation [closed]Perl 到 PHP 的翻译 [关闭]
【发布时间】:2011-03-30 03:26:30
【问题描述】:

你能把这个 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);

提前致谢。

【问题讨论】:

  • 看看cURL library
  • 关门后来的。 cURL 是一个次优的解决方案。很想看到其他没有使用它的回复。

标签: php perl translation


【解决方案1】:

给你。完整代码转换为 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);
?>

【讨论】:

    猜你喜欢
    • 2011-01-26
    • 1970-01-01
    • 2013-07-24
    • 2013-12-23
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    相关资源
    最近更新 更多