Luasocket自定义标头,404转为301 [英] Luasocket custom headers, 404 turns to 301

查看:185
本文介绍了Luasocket自定义标头,404转为301的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前的问题是使用 socket.http 模块在 lua 中获取页面标题。问题就在这里。以前,youtube网页引导我进入 404错误页面。根据 MattJ的帮助,我为自己设置了自定义主机标头请求。这就是我做的,结果是什么:



代码



  header = {host =youtube.com} 
本地结果,b,c,h = http.request {url =http://www.youtube.com/watch?v=_eT40eV7OiI,标题= header}
print(result,b,c,h)
表示k,v表示成对(c)打印(k,v)结束



结果



  1 301表:0047D430 HTTP / 1.1 301永久移动
x-content-type-options nosniff
content-length 0
expires周二,1971年4月27日19:44:06 EST
cache-control no-cache
连接关闭
位置http://www.youtube.com/watch?v=_eT40eV7OiI
content-type text / html; charset = utf-8
date星期六,2012年4月28日04:26:21 GMT
server wiseguy / 0.6.11

据我所知,错误基本上是因为 X-Content-Type-Options 价值 nosniff 。阅读文档,我知道唯一定义的值,nosniff,阻止Internet Explorer从声明的内容类型中嗅探响应。






<请帮助我,以便我可以使用自定义代理并从他们的正文中获取youtube(和上一个问题中提到的其他一些网站)标题。这是我目前拥有的完整LUA文件:

  local http = requiresocket.http
http.PROXY =http://<代理地址在这里>:8080
header = {host =youtube.com}
本地结果,b,c,h = http.request {url = http://www.youtube.com/watch?v=_eT40eV7OiI,headers = header}
print(result,b,c,h)
表示k,v表示成对(c)打印(k,v)结束


解决方案

我相信这一行应该被更改:

  header = {host =youtube.com} 

收件人:

  header = {host =www .youtube.com} 

之后,对我有用。


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:

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

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.


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" }

To:

 header = { host= "www.youtube.com" }

After that, works for me.

这篇关于Luasocket自定义标头,404转为301的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆