Luasocket自定义headers,404转301 [英] Luasocket custom headers, 404 turns to 301
问题描述
我之前的问题是关于使用 socket.http
模块在 lua 中获取页面标题.问题就在这里.以前,youtube 页面将我带到 404 错误页面.根据 MattJ 的帮助,我为请求设置了自定义 HOST
标头.这就是我所做的以及结果如何:
My previous question was about fetching page title in lua using the socket.http
module. The question lies here. Previously, youtube pages led me to a 404 error page. Based on MattJ's help, I put up custom HOST
header for the request. This is what I did and what was the result:
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
结果
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
重视 nosniff
.阅读其文档,我了解到唯一定义的值, "nosniff", 防止 Internet Explorer 从 MIME 嗅探响应远离声明的内容类型.
As far as I was able to understand from this, the error is basically because of X-Content-Type-Options
valued nosniff
. Reading its documentation, I got to know that the only defined value, "nosniff", prevents Internet Explorer from MIME-sniffing a response away from the declared content-type.
请帮助我,以便我可以使用自定义代理并从他们的正文中获取 youtube(以及上一个问题中提到的其他一些网站)标题.这是我目前拥有的完整 LUA 文件:
Please help me so that I can use custom proxy and fetch the youtube(and some other sites, as mentioned in the previous question) title from their body. Here is the complete LUA file I currently have:
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
推荐答案
我认为应该更改这一行:
I believe this line should be changed:
header = { host= "youtube.com" }
致:
header = { host= "www.youtube.com" }
在那之后,对我有用.
这篇关于Luasocket自定义headers,404转301的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!