我之前的问题是关于获取页面标题lua使用socket.http
模块。问题就在这里。之前,YouTube 页面引导我找到了一个404错误页面。基于马特吉的帮助,我自定义了HOST
请求的标头。这就是我所做的以及结果是什么:
Code
header = { host= "youtube.com" }
local result,b,c,h = http.request{ url = "http://www.youtube.com/watch?v=_eT40eV7OiI", headers = header }
print ( result, b, c, h )
for k,v in pairs(c) do print(k,v) end
Result
1 301 table: 0047D430 HTTP/1.1 301 Moved Permanently
x-content-type-options nosniff
content-length 0
expires Tue, 27 Apr 1971 19:44:06 EST
cache-control no-cache
connection close
location http://www.youtube.com/watch?v=_eT40eV7OiI
content-type text/html; charset=utf-8
date Sat, 28 Apr 2012 04:26:21 GMT
server wiseguy/0.6.11
据我所知,该错误基本上是因为X-Content-Type-Options
valued nosniff
。读其文档,我才知道唯一定义的值“nosniff”可防止 Internet Explorer 通过 MIME 嗅探声明的内容类型的响应.
请帮助我,以便我可以使用自定义代理并从其正文中获取 YouTube(以及其他一些网站,如上一个问题中提到的)标题。这是我目前拥有的完整 LUA 文件:
local http = require "socket.http"
http.PROXY="http://<proxy address here>:8080"
header = { host= "youtube.com" }
local result,b,c,h = http.request{ url = "http://www.youtube.com/watch?v=_eT40eV7OiI", headers = header }
print ( result, b, c, h )
for k,v in pairs(c) do print(k,v) end