Chinaunix首页 | 论坛 | 博客
  • 博客访问: 488191
  • 博文数量: 279
  • 博客积分: 4467
  • 博客等级: 上校
  • 技术积分: 2830
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-03 14:43
文章分类

全部博文(279)

文章存档

2013年(1)

2012年(39)

2011年(35)

2009年(29)

2008年(131)

2007年(44)

分类:

2008-04-20 20:20:56

#读取XML文件的内容,打开网页文件内容

#!/usr/bin/perl

use IO::Socket;

sub escape {
    my($toencode) = @_;
    $toencode=~s/([^a-zA-Z0-9_\-. ])/uc sprintf("%%%02x",ord($1))/eg;
    $toencode =~ tr/ /+/; # spaces become pluses

    return $toencode;
}
if ($#ARGV <= 0) {

print STDERR "usage: getright \n\n";
print STDERR " : eg. \n";
print STDERR ": eg. message.xml\n";
exit(0);
} else {
open(FILE, "<".$ARGV[1]) or die "Cannot open $ARGV[1]: $!";
}
while ($line=<FILE>)
{
# $line=~s/\n$//;

 $xml_message .= $line;
}
close(FILE);
#print $xml_message;

$xml_message=escape($xml_message);
#print $xml_message;

if ($ARGV[0] =~ (?:http://)? (.*?) (?:\:([0-9]+))? (/.*)$!x)
{ ($server,$port,$path) = ($1, $2 || 80, $3); }

$socket = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp',
Type => SOCK_STREAM) or die "Cannot connect: $!";

print $socket "GET $path?xml=$xml_message HTTP/1.1\n";
print $socket "Host: $server\n\n";

while ($data = <$socket>) {
# $data=~s/\\//g;

  print $data;
}

close($socket);

# Example HTTP return header:

#

#HTTP/1.1 200 OK

#X-Powered-By: PHP/4.1.2

#Connection: close

#Transfer-Encoding: chunked

#Content-Type: text/html


#Date: Fri, 17 Mar 2006 15:44:46 GMT

#Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/1.0.3 PHP/4.1.2 mod_perl/1.26

#Last-Modified: Fri, 17 Mar 2006 15:44:06 GMT

#ETag: "1548-dc-441ad946"

#Accept-Ranges: bytes

#Content-Length: 220

#Connection: close

#Content-Type: text/xml


# Example Content:

#

#

#

#

#

#

#

阅读(306) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~