2017-10-03 4 views
2

luasocketで 'https://translate.google.com'を取得しようとしています。同じヘッダを持つfirefoxとluasocketの違い

ヘッダーはHttpFox'es出力に基づいています。

コンテンツを取得する私の試み:

local r, c, h, fc = http.request { -- result (1 or nil on error), code (should be 200), headers, fancy code 
    url = 'http://translate.google.com'; 
    method = 'GET'; 
    sink = sink; 
    headers = { 
     ['User-Agent'] = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0'; 
     ['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; 
     ['Host'] = 'translate.google.com'; 
     ['Accept-Encoding'] = 'gzip, deflate, br'; 
     ['Accept-Language'] = 'ru,ru-RU;q=0.8,en;q=0.5,en-US;q=0.3'; 
     ['DNT'] = '1'; 
     ['Upgrade-Insecure-Requests'] = '1'; 
     ['Connection'] = 'close'; 
    }; 
} 

sinkが有効LTN12シンクです。

結果:

Code: HTTP/1.1 302 Found 
Headers: { 
    content-type : "text/html; charset=UTF-8" 
    connection : "close" 
    content-length : "226" 
    x-xss-protection : "1; mode=block" 
    p3p : "CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."" 
    server : "HTTP server (unknown)" 
    cache-control : "private, max-age=0" 
    content-language : "ru" 
    date : "Tue, 03 Oct 2017 13:50:21 GMT" 
    set-cookie : "NID=113=CO3BdznV6UYwcIZoIdF9F7dW1Cooi5ZVmNML0cQI6kA_TvfNig8xRQgS5E9dSKnIZxcfR3jxUbo3RA-7AEsqOCakciOo7Swtrcvz70Cmpm5M-_m1UQYTBBCg8VyNxzBW; expires=Wed, 04-Apr-2018 13:50:21 GMT; path=/; domain=.google.com; HttpOnly" 
    x-content-type-options : "nosniff" 
    expires : "Tue, 03 Oct 2017 13:50:21 GMT" 
    location : "https://translate.google.com/" 
} 
Body: 
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> 
<TITLE>302 Moved</TITLE></HEAD><BODY> 
<H1>302 Moved</H1> 
The document has moved 
<A HREF="https://translate.google.com/">here</A>. 
</BODY></HTML> 

私の要求の何が問題になっているのですか?なぜFirefoxは正しいページを持っているのですか?

答えて

3
Code: HTTP/1.1 302 Found 
location : "https://translate.google.com/" 

これは、HTTPSの場所へのリダイレクトですが、luasocketはhttpsで対処する方法を「知って」いないので、それはリダイレクトに従いません。 luasecをインストールし、local http = require "socket.http"local http = require "ssl.https"に置き換えた場合は、次のようなメッセージが返されます。

1 200 table: 0x000274e0 HTTP/1.1 200 OK 
関連する問題