首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >连接是否继续关闭?

连接是否继续关闭?
EN

Stack Overflow用户
提问于 2011-07-23 03:52:30
回答 2查看 781关注 0票数 0

因此,我在尝试自动登录内部网站时遇到了问题。我可以发送post请求,但在响应中我总是得到头Connection: close。我试图通过post请求传递is,但它似乎仍然响应Connection: close。我希望能够浏览整个网站,所以我需要连接: keep-alive,这样我就可以发送更多的请求。有人能告诉我我哪里做错了吗?代码如下:

代码语言:javascript
复制
#usr/bin/perl
#NetTelnet.pl

use strict; use warnings;

#Sign into cfxint Unix something...
use Net::Telnet;

# Create a new instance of Net::Telnet, 
my $telnetCon = new Net::Telnet (Timeout => 10,
                             Prompt => '/bash\$ $/') or die "Could not make connection.";

my $hostname = 'cfxint';

# Connect to the host of the users choice                                
$telnetCon->open(Host => $hostname,
             Port => 23) or die "Could not connect to $hostname.";

use WWW::Mechanize;

my $mech = WWW::Mechanize->new(cookie_jar => {});
&login_alfresco;


sub login_cxfint {
#get username and password from user
my $CXusername = '';
my $CXpassword = '';

# Recreate the login
# Wait for the login: message and then enter the username
$telnetCon->waitfor(match => '/login:/i');

# this method adds a \n to the end of the username, it mimics hitting the enter key after entering your username
$telnetCon->print($CXusername);

# does the same as the previous command but for the password
$telnetCon->print($CXpassword);

#Wait for the login successful message
$telnetCon->waitfor();
}

sub login_alfresco{

my $ALusername = '';
my $ALpassword = '';
$mech->get('http://documents.ifds.group:8080/alfresco/faces/jsp/login.jsp');

my $res = $mech->res;
my $idfaces = '';

if($res->is_success){
    my $ff = $res->content;
    if($ff =~ /id="javax.faces.ViewState" value="(.*?)"/){
         $idfaces = $1;
    }
    else {
        print "javax.faces /Regex error?\n";
        die;
    }
}

print $idfaces, "\n";

#Send the get request for Alfresco
$mech->post('http://documents.ifds.group:8080/alfresco/faces/jsp/login.jsp',[
'loginForm:rediretURL' =>,
'loginForm:user-name' => $ALusername,
'loginForm:user-password' => $ALpassword,
'loginForm:submit' => 'Login',
'loginForm_SUBMIT' => '1',
'loginForm:_idcl' => ,
'loginForm:_link_hidden_' => ,
'javax.faces.ViewState' => $idfaces], **'Connection' =>'keep-alive'**);

$res = $mech->res;

open ALF, ">Alfresco.html";
print ALF $mech->response->as_string;

if($res->is_success){
    my $ff = $res->content;
    if($ff =~ /id="javax.faces.ViewState" value="(.*?)"/){
         $idfaces = $1;
    }
    else {
        print "javax.faces /Regex error?\n";
        die;
    }
}
print $idfaces, "\n";

#Logout
$mech->post('http://documents.ifds.group:8080/alfresco/faces/jsp/extension/browse/browse.jsp', [
'browse:serach:_option' => '0',
'browse:search' => ,
'browse:spaces-pages' => '20',
'browse:content-pages' => '50',
'browse_SUBMIT' => '1',
'id' => ,
'browse:modelist' => '',
'ref'=>'',
'browse:spacesList:sort' => ,
'browse:_idJsp7' => ,
'browse:sidebar-body:navigator' => ,
'browse:contentRichList:sort' => ,
'browse:act' => 'browse:logout',
'outcome' => 'logout',
'browse:panel' => ,
'javax.faces.ViewState' => $idfaces,])
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-07-23 14:00:54

您可以使用connection cache启用keep-alive

代码语言:javascript
复制
use LWP::ConnCache;
...
$mech->conn_cache(LWP::ConnCache->new);
票数 1
EN

Stack Overflow用户

发布于 2011-07-23 04:14:09

所有的头意味着连接将在请求完成时关闭,而不是保持打开以等待可能的进一步请求。这是完全正常的,不应该影响请求的发送。

编辑:如果你正在发送一个Connection:Keep-Alive,而服务器仍然以Connection:Close作为响应,那么服务器配置就需要改变。HTTP/1.1的默认值是持久连接,因此服务器必须显式配置为发送Connection:Close。参见Section 8 of RFC2616

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6795338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档