2017-06-05 94 views
-2

讀取數據是否有反正用如何從URL

tie(*SSL, "Net::SSLeay::Handle", $host, $port); 

後讀取從使用SSL的URL數據我的代碼如下

my $a = "POST /login.php HTTP/1.1"; 
my $b = "Host: www.test.com"; 
my $c = "Connection: close"; 
my $e = "Cache-Control: max-age=0"; 
my $f = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; 
my $g = "Origin: https://www.facebook.com"; 
my $h = "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31"; 
my $i = "Content-Type: application/x-www-form-urlencoded"; 
my $j = "Accept-Encoding: gzip,deflate,sdch"; 
my $k = "Accept-Language: en-US,en;q=0.8"; 
my $l = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3"; 

my $cookie = "cookie: datr=80ZzUfKqDOjwL8pauwqMjHTa"; 
my $post = "lsd=AVpD2t1f&display=&enable_profile_selector=&legacy_return=1&next=&profile_selector_ids=&trynum=1&timezone=300&lgnrnd=031110_Euoh&lgnjs=1366193470&email=$user&pass=$user&default_persistent=0&login=Log+In"; 
my $cl = length($post); 
my $d = "Content-Length: $cl"; 


my ($host, $port) = ("www.test.com", 443); 

tie(*SSL, "Net::SSLeay::Handle", $host, $port); 




print SSL "$a\n"; 
print SSL "$b\n"; 
print SSL "$c\n"; 
print SSL "$d\n"; 
print SSL "$e\n"; 
print SSL "$f\n"; 
print SSL "$g\n"; 
print SSL "$h\n"; 
print SSL "$i\n"; 
print SSL "$j\n"; 
print SSL "$k\n"; 
print SSL "$l\n"; 
print SSL "$cookie\n\n"; 

print SSL "$post\n"; 
+3

這是用於教育目的?你爲什麼不簡單地使用LWP? – simbabque

+0

我想測試我的網站。上面的代碼使用blueforce,並通過獲取數據檢查 –

回答

2

的Net :: SSLeay的的synopsis: :把手建議只需print來處理(重點是我的)。

use Net::SSLeay::Handle qw/shutdown/; 
my ($host, $port) = ("localhost", 443); 

tie(*SSL, "Net::SSLeay::Handle", $host, $port); 

print SSL "GET/HTTP/1.0\r\n"; 
shutdown(\*SSL, 1); 
print while (<SSL>);       # <------- here 
close SSL; 
+1

對不起,我還是不明白。我想用SSL代碼獲得內容數據,我發佈了 my $ ua = LWP :: UserAgent-> new( ssl_opts => {verify_hostname => 0}, ); my $ response = $ ua-> get('https://www.facebook.com/suond.loyal'); print $ response-> content,「\ n」; –

+0

@SeaklengSay你試過這個嗎? – simbabque

+0

是啊!我曾經嘗試過很多次 –