简体   繁体   English

无法通过Perl套接字发送管道HTTP请求

[英]Unable to send pipelined http request over a perl socket

I have the following perl script to send pipelined http request over a sinlge tcp connection. 我有以下perl脚本,可通过sinlge tcp连接发送流水线的http请求。 The first request goes through and i am able to get the response. 第一个请求通过,我能够得到答复。 The second reqeust also gets sent, but no response is received for this request. 第二个请求也被发送,但是没有收到该请求的响应。 I am able to see both requests being received on the server in the trace. 我能够在跟踪中看到服务器上收到了两个请求。

use IO::Socket::INET;
$| = 1;

$socket = new IO::Socket::INET (
   PeerHost => '10.102.218.56',
   PeerPort => '80',
   Proto => 'tcp',);
die "cannot connect to the server $!\n" unless $socket;
print "connected to the server\n";

# data to send to a server
my $req = "GET /test/file5.html HTTP/1.1\r\nHost:10.102.218.50\r\nAccept: */*\r\n\r\n\r\n";
my $size = $socket->send($req);
print "1. sent data of length $size\n";

$socket->recv($response, 1024);
print "received response: $response\n";

my $req = "GET /test/file5.html HTTP/1.1\r\nHost:10.102.218.50\r\nAccept: */*\r\n\r\n\r\n";
my $size = $socket->send($req);
print "1. sent data of length $size\n";

$socket->recv($response, 1024);
print "received response: $response\n";
sleep 1;
$socket->close();

On the Apache access_log i see only one instance of the HTTP request being received : 在Apache access_log上,我仅收到一个HTTP请求实例:

10.102.218.50 - - [02/Sep/2014:23:04:50 +0530] "GET /test/file5.html HTTP/1.1" 200 6 "-" "-"

I am guessing that I am missing some characters that indicate the end of an HTTP request of the server. 我猜想我缺少一些指示服务器HTTP请求结束的字符。 But i am not able to find what they are. 但是我找不到他们是什么。

What am i doing wrong here? 我在这里做错了什么?

Edit: Could the Apache server be closing the connection after the first HTTP request is answered. 编辑:回答第一个HTTP请求后,Apache服务器是否可以关闭连接。 Is there a setting for this? 有这个设置吗?

Edit2: KeepAlive was set to Off on my apache server. Edit2:在我的apache服务器上,KeepAlive设置为Off。 Setting it to ON fixes the issue. 将其设置为ON可解决此问题。

Found the problem. 找到了问题。 The KeepAlive was set to off on my Apache server. 我的Apache服务器上的KeepAlive设置为关闭。 Setting the KeepAlive to On fixed the problem. 将KeepAlive设置为On可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM