赞 | 0 |
VIP | 12 |
好人卡 | 42 |
积分 | 7 |
经验 | 44348 |
最后登录 | 2024-4-1 |
在线时间 | 791 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 687
- 在线时间
- 791 小时
- 注册时间
- 2011-10-20
- 帖子
- 2394
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
- 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, 1)
- 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,length,bk)
- content = ""
-
- read_size = 1024 # 一次读入文件的尺寸
- irf = Win32API.new('wininet', 'InternetReadFile', %(l, p, i, p), 'i')
- bk.call(0,length)
- id=0
- while(true)
- buf = "\0" * read_size
- red = [0].pack('L')
- irf.call( hService, buf, read_size, red)
- bk.call(id*read_size,length)
- id+=1
- # 读到文件末端
- break if (red.unpack('L') == [0])
- #buf.delete!("\0")
- buf = buf[0, red.unpack('L')[0]]
- content += buf
- end
- return content
- end
-
- HTTP_QUERY_STATUS_CODE = 19
- CONTENT_LENGTH=5
- 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.HttpQuerySize(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, CONTENT_LENGTH, buf, red, nil)
- buf.delete!("\0")
- return buf
- end
- 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,bk)
- info = nil
- # begin
- hInternet = InternetOpen()
- if (hInternet != 0)
- hService = InternetOpenUrl(hInternet, url)
-
- if (hService != 0)
- status_code = HttpQueryInfo(hService)
- length=HttpQuerySize(hService).to_i
- if (status_code == HTTP_CODE_OK)
- #a=File.open(pathname,"wb")
- info = InternetReadFile(hService,length,bk)
- end
- InternetCloseHandle(hService)
- end
- InternetCloseHandle(hInternet)
- end
- #rescue
- # 例外发生
- # return nil
- #end
-
- return info
- end
-
- end
复制代码 脚本是利用IE的,我以前就发现读取一个php或者其他页面如txt,他返回的是旧的页面。
我们一定访问到了缓存,查了wininet啥也不懂,
把开头的INTERNET_OPEN_TYPE_DIRECT = 0
改成INTERNET_OPEN_TYPE_DIRECT = 1
资料:
function InternetOpen(lpszAgent: PChar;
dwAccessType: DWORD;
lpszProxy,
lpszProxyBypass:PChar;
dwFlags: DWORD
dwFlags
标记,一般设置为
0
,可以是:
1
、
INTERNET_FLAG_DONT_CACHE
不在缓存中保存取得的内容
2
、
INTERNET_FLAG_OFFLINE
脱机方式
---------------------------------------------------------
改成1之后,还是读取到了旧的信息(post之后无刷新网页的旧页面)
---------------------------------------------------------
查阅相关之后,俺被API逼疯了,后来终于得到了一种解决办法:
在那个读取的php后面改成php?xx=rand xxx
以使得IE“自作聪明”的优化得以屏蔽
也就是ruby代码:"http://xxx.net/cs.php?a=#{rand 1000000000}"
之后就躲开了他的缓存,
求讨论一下,各位大触,如何不用这种渣办法,(参数之类的办法)禁止缓存? |
|