具有相同标头的firefox和luasocket之间的区别

时间:2017-10-03 13:54:58

标签: https lua google-translate luasocket

我试图获得' https://translate.google.com'通过luasocket

标题基于HttpFox&es; 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 sink;

结果:

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得到正确的页面而我呢?

1 个答案:

答案 0 :(得分: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