Project1
标题:
求RM可用的HTTP GET
[打印本页]
作者:
zh99998
时间:
2010-8-21 15:15
标题:
求RM可用的HTTP GET
所谓的HTTP GET就是访问一个网页并且读取内容
ruby里的http类需要加载socket.so,这个RM加载不了
我把从网游脚本里抠出来的socket类塞进来也不能用,看起来是执行gethostbyname那个API的时候失败(返回0)
求RM可用的HTTP GET
作者:
八云紫
时间:
2010-8-21 15:38
用 WSAGetLastError 获取错误代码看看~~~
作者:
尘羽泯
时间:
2010-8-21 16:07
class Get_Http_Info
AGENT = "RGSS PLAYER"
INTERNET_OPEN_TYPE_PRECONFIG = 0 # IEの設定を仕様
INTERNET_OPEN_TYPE_DIRECT = 1 # プロキシを使用しない
def Get_Http_Info.InternetOpen()
io = Win32API.new('wininet', 'InternetOpen', %(p, l, p, p, l), 'l')
hInternet = io.call(AGENT, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
return hInternet
end
def Get_Http_Info.InternetOpenUrl(hSession, url)
iou = Win32API.new('wininet', 'InternetOpenUrl', %(l, p, p, l, l, l), 'l')
hService = iou.call(hSession, url, nil, 0, 0, 0)
return hService
end
def Get_Http_Info.InternetReadFile(hService)
content = ""
read_size = 1024 # 一次读入文件的尺寸
irf = Win32API.new('wininet', 'InternetReadFile', %(l, p, i, p), 'i')
while(true)
buf = "\0" * read_size
red = [0].pack('L')
irf.call( hService, buf, read_size, red )
if(red.unpack('L') == [0])
#读到文件末端
break
end
buf.delete!("\0")
content += buf
end
return content
end
HTTP_QUERY_STATUS_CODE = 19
def Get_Http_Info.HttpQueryInfo(hService)
read_size = 1024
buf = "\0" * read_size
red = [read_size-1].pack('L')
hqi = Win32API.new('wininet', 'HttpQueryInfo', %(l, l, p, p, p), 'i')
isOk = hqi.call( hService, HTTP_QUERY_STATUS_CODE, buf, red, nil)
buf.delete!("\0")
return buf
end
def Get_Http_Info.InternetCloseHandle(hInternet)
ich = Win32API.new('winInet', 'InternetCloseHandle', %(l), 'i')
isOk = ich.call(hInternet)
return isOk
end
HTTP_CODE_OK = "200"
def Get_Http_Info.get_info(url)
info = nil
begin
hInternet = InternetOpen()
if(hInternet != 0)
hService = InternetOpenUrl(hInternet, url)
if(hService != 0)
status_code = HttpQueryInfo(hService)
if(status_code == HTTP_CODE_OK)
info = InternetReadFile(hService)
end
InternetCloseHandle(hService)
end
InternetCloseHandle(hInternet)
end
rescue
# 例外发生
return nil
end
ary = []
info.each_line do |line|
next if line.empty?
ary.push line
end
return ary[271].scan(/\w+<\/a>/)
end
def Get_Http_Info.get_html(url)
info = nil
begin
hInternet = InternetOpen()
if(hInternet != 0)
hService = InternetOpenUrl(hInternet, url)
if(hService != 0)
status_code = HttpQueryInfo(hService)
if(status_code == HTTP_CODE_OK)
info = InternetReadFile(hService)
end
InternetCloseHandle(hService)
end
InternetCloseHandle(hInternet)
end
rescue
# 例外发生
return nil
end
return info
end
end
复制代码
鄙视楼主这类的SSD!!哼!!
作者:
zh99998
时间:
2010-8-21 16:30
回复
尘羽泯
的帖子
谢谢><
作者:
紫苏
时间:
2010-8-22 01:03
RM 的 socket 用不了还有 Windows 的 socket
不过二楼给的那个脚本倒是足够了,叶子的《6R之眼》里用到过
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1