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
  1. class Get_Http_Info

  2. AGENT = "RGSS PLAYER"
  3. INTERNET_OPEN_TYPE_PRECONFIG = 0 # IEの設定を仕様
  4. INTERNET_OPEN_TYPE_DIRECT = 1 # プロキシを使用しない
  5. def Get_Http_Info.InternetOpen()
  6. io = Win32API.new('wininet', 'InternetOpen', %(p, l, p, p, l), 'l')
  7. hInternet = io.call(AGENT, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
  8. return hInternet
  9. end

  10. def Get_Http_Info.InternetOpenUrl(hSession, url)
  11. iou = Win32API.new('wininet', 'InternetOpenUrl', %(l, p, p, l, l, l), 'l')
  12. hService = iou.call(hSession, url, nil, 0, 0, 0)
  13. return hService
  14. end

  15. def Get_Http_Info.InternetReadFile(hService)
  16. content = ""
  17. read_size = 1024 # 一次读入文件的尺寸
  18. irf = Win32API.new('wininet', 'InternetReadFile', %(l, p, i, p), 'i')
  19. while(true)
  20. buf = "\0" * read_size
  21. red = [0].pack('L')
  22. irf.call( hService, buf, read_size, red )
  23. if(red.unpack('L') == [0])
  24. #读到文件末端
  25. break
  26. end
  27. buf.delete!("\0")
  28. content += buf
  29. end

  30. return content
  31. end

  32. HTTP_QUERY_STATUS_CODE = 19

  33. def Get_Http_Info.HttpQueryInfo(hService)
  34. read_size = 1024
  35. buf = "\0" * read_size
  36. red = [read_size-1].pack('L')
  37. hqi = Win32API.new('wininet', 'HttpQueryInfo', %(l, l, p, p, p), 'i')
  38. isOk = hqi.call( hService, HTTP_QUERY_STATUS_CODE, buf, red, nil)
  39. buf.delete!("\0")
  40. return buf
  41. end

  42. def Get_Http_Info.InternetCloseHandle(hInternet)
  43. ich = Win32API.new('winInet', 'InternetCloseHandle', %(l), 'i')
  44. isOk = ich.call(hInternet)
  45. return isOk
  46. end

  47. HTTP_CODE_OK = "200"

  48. def Get_Http_Info.get_info(url)
  49. info = nil
  50. begin
  51. hInternet = InternetOpen()
  52. if(hInternet != 0)
  53. hService = InternetOpenUrl(hInternet, url)
  54. if(hService != 0)
  55. status_code = HttpQueryInfo(hService)
  56. if(status_code == HTTP_CODE_OK)
  57. info = InternetReadFile(hService)
  58. end
  59. InternetCloseHandle(hService)
  60. end
  61. InternetCloseHandle(hInternet)
  62. end
  63. rescue
  64. # 例外发生
  65. return nil
  66. end

  67. ary = []

  68. info.each_line do |line|
  69. next if line.empty?
  70. ary.push line
  71. end

  72. return ary[271].scan(/\w+<\/a>/)

  73. end


  74. def Get_Http_Info.get_html(url)
  75. info = nil
  76. begin
  77. hInternet = InternetOpen()
  78. if(hInternet != 0)
  79. hService = InternetOpenUrl(hInternet, url)
  80. if(hService != 0)
  81. status_code = HttpQueryInfo(hService)
  82. if(status_code == HTTP_CODE_OK)
  83. info = InternetReadFile(hService)
  84. end
  85. InternetCloseHandle(hService)
  86. end
  87. InternetCloseHandle(hInternet)
  88. end
  89. rescue
  90. # 例外发生
  91. return nil
  92. end
  93. return info
  94. end
  95. 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