注册会员 登录
Project1 返回首页

zh99998的个人空间 https://rpg.blue/?42757 [收藏] [复制] [分享] [RSS]

日志

RM可用的HTTP

热度 1已有 596 次阅读2010-11-18 15:53 |个人分类:Ruby|

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

鸡蛋
1

鲜花

刚表态过的朋友 (1 人)

评论 (0 个评论)

facelist doodle 涂鸦笔

您需要登录后才可以评论 登录 | 注册会员

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2021-12-4 12:03

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部