Guest User

Untitled

a guest
Sep 29th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 73.03 KB | None | 0 0
  1. Imports Microsoft.VisualBasic
  2. Imports Microsoft.VisualBasic.CompilerServices
  3. Imports System
  4. Imports System.Collections.Generic
  5. Imports System.Collections.Specialized
  6. Imports System.Drawing
  7. Imports System.Drawing.Imaging
  8. Imports System.IO
  9. Imports System.IO.Compression
  10. Imports System.Net
  11. Imports System.Net.Configuration
  12. Imports System.Net.Security
  13. Imports System.Reflection
  14. Imports System.Runtime.CompilerServices
  15. Imports System.Runtime.InteropServices
  16. Imports System.Security.Cryptography.X509Certificates
  17. Imports System.Text
  18. Imports System.Text.RegularExpressions
  19. Public Class Http
  20. Implements IDisposable
  21. ' Methods
  22. Shared Sub New()
  23. Dim dictionary As New Dictionary(Of String, String)
  24. dictionary.Add("ai", "application/postscript")
  25. dictionary.Add("aif", "audio/x-aiff")
  26. dictionary.Add("aifc", "audio/x-aiff")
  27. dictionary.Add("aiff", "audio/x-aiff")
  28. dictionary.Add("asc", "text/plain")
  29. dictionary.Add("atom", "application/atom+xml")
  30. dictionary.Add("au", "audio/basic")
  31. dictionary.Add("avi", "video/x-msvideo")
  32. dictionary.Add("bcpio", "application/x-bcpio")
  33. dictionary.Add("bin", "application/octet-stream")
  34. dictionary.Add("bmp", "image/bmp")
  35. dictionary.Add("cdf", "application/x-netcdf")
  36. dictionary.Add("cgm", "image/cgm")
  37. dictionary.Add("class", "application/octet-stream")
  38. dictionary.Add("cpio", "application/x-cpio")
  39. dictionary.Add("cpt", "application/mac-compactpro")
  40. dictionary.Add("csh", "application/x-csh")
  41. dictionary.Add("css", "text/css")
  42. dictionary.Add("dcr", "application/x-director")
  43. dictionary.Add("dif", "video/x-dv")
  44. dictionary.Add("dir", "application/x-director")
  45. dictionary.Add("djv", "image/vnd.djvu")
  46. dictionary.Add("djvu", "image/vnd.djvu")
  47. dictionary.Add("dll", "application/octet-stream")
  48. dictionary.Add("dmg", "application/octet-stream")
  49. dictionary.Add("dms", "application/octet-stream")
  50. dictionary.Add("doc", "application/msword")
  51. dictionary.Add("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
  52. dictionary.Add("dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template")
  53. dictionary.Add("docm", "application/vnd.ms-word.document.macroEnabled.12")
  54. dictionary.Add("dotm", "application/vnd.ms-word.template.macroEnabled.12")
  55. dictionary.Add("dtd", "application/xml-dtd")
  56. dictionary.Add("dv", "video/x-dv")
  57. dictionary.Add("dvi", "application/x-dvi")
  58. dictionary.Add("dxr", "application/x-director")
  59. dictionary.Add("eps", "application/postscript")
  60. dictionary.Add("etx", "text/x-setext")
  61. dictionary.Add("exe", "application/octet-stream")
  62. dictionary.Add("ez", "application/andrew-inset")
  63. dictionary.Add("gif", "image/gif")
  64. dictionary.Add("gram", "application/srgs")
  65. dictionary.Add("grxml", "application/srgs+xml")
  66. dictionary.Add("gtar", "application/x-gtar")
  67. dictionary.Add("hdf", "application/x-hdf")
  68. dictionary.Add("hqx", "application/mac-binhex40")
  69. dictionary.Add("htm", "text/html")
  70. dictionary.Add("html", "text/html")
  71. dictionary.Add("ice", "x-conference/x-cooltalk")
  72. dictionary.Add("ico", "image/x-icon")
  73. dictionary.Add("ics", "text/calendar")
  74. dictionary.Add("ief", "image/ief")
  75. dictionary.Add("ifb", "text/calendar")
  76. dictionary.Add("iges", "model/iges")
  77. dictionary.Add("igs", "model/iges")
  78. dictionary.Add("jnlp", "application/x-java-jnlp-file")
  79. dictionary.Add("jp2", "image/jp2")
  80. dictionary.Add("jpe", "image/jpeg")
  81. dictionary.Add("jpeg", "image/jpeg")
  82. dictionary.Add("jpg", "image/jpeg")
  83. dictionary.Add("js", "application/x-javascript")
  84. dictionary.Add("kar", "audio/midi")
  85. dictionary.Add("latex", "application/x-latex")
  86. dictionary.Add("lha", "application/octet-stream")
  87. dictionary.Add("lzh", "application/octet-stream")
  88. dictionary.Add("m3u", "audio/x-mpegurl")
  89. dictionary.Add("m4a", "audio/mp4a-latm")
  90. dictionary.Add("m4b", "audio/mp4a-latm")
  91. dictionary.Add("m4p", "audio/mp4a-latm")
  92. dictionary.Add("m4u", "video/vnd.mpegurl")
  93. dictionary.Add("m4v", "video/x-m4v")
  94. dictionary.Add("mac", "image/x-macpaint")
  95. dictionary.Add("man", "application/x-troff-man")
  96. dictionary.Add("mathml", "application/mathml+xml")
  97. dictionary.Add("me", "application/x-troff-me")
  98. dictionary.Add("mesh", "model/mesh")
  99. dictionary.Add("mid", "audio/midi")
  100. dictionary.Add("midi", "audio/midi")
  101. dictionary.Add("mif", "application/vnd.mif")
  102. dictionary.Add("mov", "video/quicktime")
  103. dictionary.Add("movie", "video/x-sgi-movie")
  104. dictionary.Add("mp2", "audio/mpeg")
  105. dictionary.Add("mp3", "audio/mpeg")
  106. dictionary.Add("mp4", "video/mp4")
  107. dictionary.Add("mpe", "video/mpeg")
  108. dictionary.Add("mpeg", "video/mpeg")
  109. dictionary.Add("mpg", "video/mpeg")
  110. dictionary.Add("mpga", "audio/mpeg")
  111. dictionary.Add("ms", "application/x-troff-ms")
  112. dictionary.Add("msh", "model/mesh")
  113. dictionary.Add("mxu", "video/vnd.mpegurl")
  114. dictionary.Add("nc", "application/x-netcdf")
  115. dictionary.Add("oda", "application/oda")
  116. dictionary.Add("ogg", "application/ogg")
  117. dictionary.Add("pbm", "image/x-portable-bitmap")
  118. dictionary.Add("pct", "image/pict")
  119. dictionary.Add("pdb", "chemical/x-pdb")
  120. dictionary.Add("pdf", "application/pdf")
  121. dictionary.Add("pgm", "image/x-portable-graymap")
  122. dictionary.Add("pgn", "application/x-chess-pgn")
  123. dictionary.Add("pic", "image/pict")
  124. dictionary.Add("pict", "image/pict")
  125. dictionary.Add("png", "image/png")
  126. dictionary.Add("pnm", "image/x-portable-anymap")
  127. dictionary.Add("pnt", "image/x-macpaint")
  128. dictionary.Add("pntg", "image/x-macpaint")
  129. dictionary.Add("ppm", "image/x-portable-pixmap")
  130. dictionary.Add("ppt", "application/vnd.ms-powerpoint")
  131. dictionary.Add("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation")
  132. dictionary.Add("potx", "application/vnd.openxmlformats-officedocument.presentationml.template")
  133. dictionary.Add("ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow")
  134. dictionary.Add("ppam", "application/vnd.ms-powerpoint.addin.macroEnabled.12")
  135. dictionary.Add("pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12")
  136. dictionary.Add("potm", "application/vnd.ms-powerpoint.template.macroEnabled.12")
  137. dictionary.Add("ppsm", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12")
  138. dictionary.Add("ps", "application/postscript")
  139. dictionary.Add("qt", "video/quicktime")
  140. dictionary.Add("qti", "image/x-quicktime")
  141. dictionary.Add("qtif", "image/x-quicktime")
  142. dictionary.Add("ra", "audio/x-pn-realaudio")
  143. dictionary.Add("ram", "audio/x-pn-realaudio")
  144. dictionary.Add("ras", "image/x-cmu-raster")
  145. dictionary.Add("rdf", "application/rdf+xml")
  146. dictionary.Add("rgb", "image/x-rgb")
  147. dictionary.Add("rm", "application/vnd.rn-realmedia")
  148. dictionary.Add("roff", "application/x-troff")
  149. dictionary.Add("rtf", "text/rtf")
  150. dictionary.Add("rtx", "text/richtext")
  151. dictionary.Add("sgm", "text/sgml")
  152. dictionary.Add("sgml", "text/sgml")
  153. dictionary.Add("sh", "application/x-sh")
  154. dictionary.Add("shar", "application/x-shar")
  155. dictionary.Add("silo", "model/mesh")
  156. dictionary.Add("sit", "application/x-stuffit")
  157. dictionary.Add("skd", "application/x-koan")
  158. dictionary.Add("skm", "application/x-koan")
  159. dictionary.Add("skp", "application/x-koan")
  160. dictionary.Add("skt", "application/x-koan")
  161. dictionary.Add("smi", "application/smil")
  162. dictionary.Add("smil", "application/smil")
  163. dictionary.Add("snd", "audio/basic")
  164. dictionary.Add("so", "application/octet-stream")
  165. dictionary.Add("spl", "application/x-futuresplash")
  166. dictionary.Add("src", "application/x-wais-source")
  167. dictionary.Add("sv4cpio", "application/x-sv4cpio")
  168. dictionary.Add("sv4crc", "application/x-sv4crc")
  169. dictionary.Add("svg", "image/svg+xml")
  170. dictionary.Add("swf", "application/x-shockwave-flash")
  171. dictionary.Add("t", "application/x-troff")
  172. dictionary.Add("tar", "application/x-tar")
  173. dictionary.Add("tcl", "application/x-tcl")
  174. dictionary.Add("tex", "application/x-tex")
  175. dictionary.Add("texi", "application/x-texinfo")
  176. dictionary.Add("texinfo", "application/x-texinfo")
  177. dictionary.Add("tif", "image/tiff")
  178. dictionary.Add("tiff", "image/tiff")
  179. dictionary.Add("tr", "application/x-troff")
  180. dictionary.Add("tsv", "text/tab-separated-values")
  181. dictionary.Add("txt", "text/plain")
  182. dictionary.Add("ustar", "application/x-ustar")
  183. dictionary.Add("vcd", "application/x-cdlink")
  184. dictionary.Add("vrml", "model/vrml")
  185. dictionary.Add("vxml", "application/voicexml+xml")
  186. dictionary.Add("wav", "audio/x-wav")
  187. dictionary.Add("wbmp", "image/vnd.wap.wbmp")
  188. dictionary.Add("wbmxl", "application/vnd.wap.wbxml")
  189. dictionary.Add("wml", "text/vnd.wap.wml")
  190. dictionary.Add("wmlc", "application/vnd.wap.wmlc")
  191. dictionary.Add("wmls", "text/vnd.wap.wmlscript")
  192. dictionary.Add("wmlsc", "application/vnd.wap.wmlscriptc")
  193. dictionary.Add("wrl", "model/vrml")
  194. dictionary.Add("xbm", "image/x-xbitmap")
  195. dictionary.Add("xht", "application/xhtml+xml")
  196. dictionary.Add("xhtml", "application/xhtml+xml")
  197. dictionary.Add("xls", "application/vnd.ms-excel")
  198. dictionary.Add("xml", "application/xml")
  199. dictionary.Add("xpm", "image/x-xpixmap")
  200. dictionary.Add("xsl", "application/xml")
  201. dictionary.Add("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  202. dictionary.Add("xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template")
  203. dictionary.Add("xlsm", "application/vnd.ms-excel.sheet.macroEnabled.12")
  204. dictionary.Add("xltm", "application/vnd.ms-excel.template.macroEnabled.12")
  205. dictionary.Add("xlam", "application/vnd.ms-excel.addin.macroEnabled.12")
  206. dictionary.Add("xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12")
  207. dictionary.Add("xslt", "application/xslt+xml")
  208. dictionary.Add("xul", "application/vnd.mozilla.xul+xml")
  209. dictionary.Add("xwd", "image/x-xwindowdump")
  210. dictionary.Add("xyz", "chemical/x-xyz")
  211. dictionary.Add("zip", "application/zip")
  212. Http.MIMETypes = dictionary
  213. End Sub
  214.  
  215. Public Sub New()
  216. Me.SetUnsafeHeaderParsing(True)
  217. ServicePointManager.DefaultConnectionLimit = 500
  218. ServicePointManager.Expect100Continue = Me.AllowExpect100
  219. ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf Me.AcceptAllCertifications)
  220. ServicePointManager.UseNagleAlgorithm = False
  221. ServicePointManager.SecurityProtocol = (SecurityProtocolType.Tls Or SecurityProtocolType.Ssl3)
  222. Me.SessionCookies = New List(Of HttpCookie)
  223. End Sub
  224.  
  225. Private Function AcceptAllCertifications(ByVal sender As Object, ByVal certification As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
  226. Return True
  227. End Function
  228.  
  229. Public Sub AddCookie(ByVal c As HttpCookie)
  230. Me.SessionCookies.Add(c)
  231. End Sub
  232.  
  233. Public Sub AddCookie(ByVal c As HttpCookie())
  234. Me.SessionCookies.AddRange(c)
  235. End Sub
  236.  
  237. Public Shared Function Base36Decode(ByVal Data As String) As Long
  238. Dim bytes As Byte() = Convert.FromBase64String(Data)
  239. Return Conversions.ToLong(Encoding.UTF8.GetString(bytes))
  240. End Function
  241.  
  242. Public Shared Function Base36Encode(ByVal Data As Long) As String
  243. Dim chArray As Char() = "0123456789abcdefghijklmnopqrstuvwxyz".ToCharArray
  244. Dim stack As New Stack(Of Char)
  245. Do While Not Data.Equals(CLng(0))
  246. stack.Push(chArray(CInt(Convert.ToInt64(CLng((Data Mod &H24))))))
  247. Data = Convert.ToInt64(CDbl((CDbl(Data) / 36)))
  248. Loop
  249. Return New String(stack.ToArray)
  250. End Function
  251.  
  252. Public Shared Function Base64ToImage(ByVal [Text] As String) As Image
  253. Try
  254. Dim buffer As Byte() = Convert.FromBase64String([Text])
  255. Using stream As MemoryStream = New MemoryStream(buffer, 0, buffer.Length)
  256. stream.Write(buffer, 0, buffer.Length)
  257. Return Image.FromStream(stream, True)
  258. End Using
  259. Catch exception1 As Exception
  260. ProjectData.SetProjectError(exception1)
  261. Dim ex As Exception = exception1
  262. ProjectData.SetProjectError(ex)
  263. ProjectData.ClearProjectError()
  264. ProjectData.ClearProjectError()
  265. End Try
  266. Return Nothing
  267. End Function
  268.  
  269. Public Sub ClearCookies()
  270. Me.SessionCookies.Clear()
  271. End Sub
  272.  
  273. Public Shared Function CountOccurance(ByVal Data As String, ByVal Search As String, Optional ByVal CaseSensitive As Boolean = False) As Integer
  274. Return Convert.ToInt32(CDbl((CDbl(Convert.ToInt32(RuntimeHelpers.GetObjectValue(RuntimeHelpers.GetObjectValue(RuntimeHelpers.GetObjectValue(Interaction.IIf(CaseSensitive, (Data.Length - Data.Replace(Search, "").Length), (Data.Length - Data.ToLower.Replace(Search.ToLower, "").Length))))))) / CDbl(Search.Length))))
  275. End Function
  276.  
  277. Public Sub Dispose() Implements IDisposable.Dispose
  278. Me.Dispose(True)
  279. GC.SuppressFinalize(Me)
  280. End Sub
  281.  
  282. Protected Overridable Sub Dispose(ByVal disposing As Boolean)
  283. If (Not Me.disposedValue AndAlso disposing) Then
  284. Me.RedirectBlacklist.Clear()
  285. Me.SessionCookies.Clear()
  286. End If
  287. Me.disposedValue = True
  288. End Sub
  289.  
  290. Public Function DownloadFile(ByVal Path As String, ByVal Url As String) As HttpResponse
  291. Dim response2 As New HttpResponse
  292. Dim expression As Exception = Nothing
  293. Dim client As New WebClient
  294. Try
  295. Dim client2 As WebClient = client
  296. If Not String.IsNullOrEmpty(Me.Referer) Then
  297. client2.Headers.Add(HttpRequestHeader.Referer, Me.Referer)
  298. End If
  299. If Me.SendCookies Then
  300. Dim str As String = Interaction.IIf(Me.UseCustomCookies, Me.GetCookies(Me.CustomCookies), Me.GetCookies(Url)).ToString
  301. If Not String.IsNullOrEmpty(str) Then
  302. client2.Headers.Add(HttpRequestHeader.Cookie, str)
  303. End If
  304. End If
  305. If Not String.IsNullOrEmpty(Me.Proxy.Server) Then
  306. client2.Proxy = New WebProxy(Me.Proxy.Server, Me.Proxy.Port)
  307. If Not String.IsNullOrEmpty(Me.Proxy.UserName) Then
  308. client2.Proxy.Credentials = New NetworkCredential(Me.Proxy.UserName, Me.Proxy.Password)
  309. End If
  310. End If
  311. client2.DownloadFile(Url, Path)
  312. client2 = Nothing
  313. Catch exception1 As Exception
  314. ProjectData.SetProjectError(exception1)
  315. Dim ex As Exception = exception1
  316. ProjectData.SetProjectError(ex)
  317. expression = ex
  318. ProjectData.ClearProjectError()
  319. ProjectData.ClearProjectError()
  320. Finally
  321. client.Dispose()
  322. If Not Information.IsNothing(expression) Then
  323. response2.Error = Me.ProcessException(expression)
  324. End If
  325. End Try
  326. Return response2
  327. End Function
  328.  
  329. Public Shared Function EscapeUnicode(ByVal Data As String) As String
  330. Return Regex.Unescape(Data)
  331. End Function
  332.  
  333. Public Function FindCookie(ByVal Name As String) As HttpCookie
  334. Dim cookie As HttpCookie
  335. For Each cookie In Me.SessionCookies
  336. If (cookie.Name = Name) Then
  337. Return cookie
  338. End If
  339. Next
  340. Return Nothing
  341. End Function
  342.  
  343. Public Function FindCookie(ByVal Name As String, ByVal Domain As String) As HttpCookie
  344. Dim cookie As HttpCookie
  345. For Each cookie In Me.SessionCookies
  346. If ((cookie.Name = Name) AndAlso (cookie.Domain = Domain)) Then
  347. Return cookie
  348. End If
  349. Next
  350. Return Nothing
  351. End Function
  352.  
  353. <DllImport("urlmon.dll", CharSet:=CharSet.Auto)> _
  354. Private Shared Function FindMimeFromData(ByVal pBC As UInt32, <MarshalAs(UnmanagedType.LPStr)> ByVal pwzUrl As String, <MarshalAs(UnmanagedType.LPArray)> ByVal pBuffer As Byte(), ByVal cbSize As UInt32, <MarshalAs(UnmanagedType.LPStr)> ByVal pwzMimeProposed As String, ByVal dwMimeFlags As UInt32, ByRef ppwzMimeOut As UInt32, ByVal dwReserverd As UInt32) As UInt32
  355. End Function
  356.  
  357. Public Shared Function FixData(ByVal Data As String) As String
  358. Return Data.Replace("\u003e", ">").Replace("\u003c", "<").Replace("\u003a", ":").Replace("\u003b", ";").Replace("\u003f", "?").Replace("\u003d", "=").Replace("\u002f", "/").Replace("\u0026", "&").Replace("\u002b", "+").Replace("\u0025", "%").Replace("\u0027", "'").Replace("\u007b", "{").Replace("\u007d", "}").Replace("\u007c", "|").Replace("\u0022", """").Replace("\u0023", "#").Replace("\u0021", "!").Replace("\u0024", "$").Replace("\u0040", "@").Replace("\002f", "/").Replace("\r\n", ChrW(13) & ChrW(10) & ChrW(13) & ChrW(10)).Replace("\n", ChrW(13) & ChrW(10)).Replace("\x3a", ":").Replace("\x2f", "/").Replace("\x3f", "?").Replace("\x3d", "=").Replace("\x26", "&").Replace("\&", "&").Replace("\/\/", "//").Replace("\\", "\").Replace("\""", """").Replace("\/", "/")
  359. End Function
  360.  
  361. Public Shared Function GenerateGuid() As String
  362. Return Guid.NewGuid.ToString.Replace("-", "")
  363. End Function
  364.  
  365. Public Function GetAllCookies() As List(Of HttpCookie)
  366. Return Me.SessionCookies
  367. End Function
  368.  
  369. Public Function GetCookies(ByVal Names As String()) As HttpCookie()
  370. Dim list As New List(Of HttpCookie)
  371. Dim str As String
  372. For Each str In Names
  373. Dim expression As HttpCookie = Me.FindCookie(str)
  374. If Not Information.IsNothing(expression) Then
  375. list.Add(expression)
  376. End If
  377. Next
  378. Return list.ToArray
  379. End Function
  380.  
  381. Private Function GetCookies(ByVal Cookies As HttpCookie()) As String
  382. Dim str2 As String = String.Empty
  383. If Not Information.IsNothing(Cookies) Then
  384. Dim cookieArray As HttpCookie() = Cookies
  385. If (cookieArray.Length = 0) Then
  386. Return str2
  387. End If
  388. Dim cookie As HttpCookie
  389. For Each cookie In Cookies
  390. str2 = (str2 & cookie.Name & Interaction.IIf(String.IsNullOrEmpty(cookie.Value), "", ("=" & cookie.Value)).ToString & "; ")
  391. Next
  392. If str2.EndsWith("; ") Then
  393. str2 = str2.Substring(0, (str2.Length - 2))
  394. End If
  395. cookieArray = Nothing
  396. End If
  397. Return str2
  398. End Function
  399.  
  400. Private Function GetCookies(ByVal RequestUri As String) As String
  401. Dim str2 As String = String.Empty
  402. If RequestUri.StartsWith("https://") Then
  403. RequestUri = ("http://" & RequestUri.Substring((RequestUri.IndexOf("//") + 2)))
  404. End If
  405. If Not RequestUri.StartsWith("http") Then
  406. RequestUri = ("http://" & RequestUri)
  407. End If
  408. Dim uri As New Uri(RequestUri)
  409. If Not Information.IsNothing(Me.SessionCookies) Then
  410. If (Me.SessionCookies.Count <> 0) Then
  411. Dim cookie As HttpCookie
  412. For Each cookie In Me.SessionCookies
  413. If (cookie.Domain.ToLower.Trim = uri.Host.ToLower.Trim) Then
  414. str2 = (str2 & cookie.Name & Interaction.IIf(String.IsNullOrEmpty(cookie.Value), "", ("=" & cookie.Value)).ToString & "; ")
  415. ElseIf (cookie.Domain.StartsWith(".") AndAlso uri.Host.Contains(cookie.Domain)) Then
  416. str2 = (str2 & cookie.Name & Interaction.IIf(String.IsNullOrEmpty(cookie.Value), "", ("=" & cookie.Value)).ToString & "; ")
  417. ElseIf (cookie.Domain.StartsWith(".") AndAlso (Http.CountOccurance(uri.Host, ".", False) = 1)) Then
  418. str2 = (str2 & cookie.Name & Interaction.IIf(String.IsNullOrEmpty(cookie.Value), "", ("=" & cookie.Value)).ToString & "; ")
  419. ElseIf cookie.Domain.Contains(uri.Host) Then
  420. str2 = (str2 & cookie.Name & Interaction.IIf(String.IsNullOrEmpty(cookie.Value), "", ("=" & cookie.Value)).ToString & "; ")
  421. End If
  422. Next
  423. If str2.EndsWith("; ") Then
  424. str2 = str2.Substring(0, (str2.Length - 2))
  425. End If
  426. End If
  427. Return str2
  428. End If
  429. Me.SessionCookies = New List(Of HttpCookie)
  430. Return str2
  431. End Function
  432.  
  433. Public Function GetCookies(ByVal Names As String(), ByVal Domain As String) As HttpCookie()
  434. Dim list As New List(Of HttpCookie)
  435. Dim str As String
  436. For Each str In Names
  437. Dim expression As HttpCookie = Me.FindCookie(str, Domain)
  438. If Not Information.IsNothing(expression) Then
  439. list.Add(expression)
  440. End If
  441. Next
  442. Return list.ToArray
  443. End Function
  444.  
  445. Public Shared Function GetMIMEType(ByVal FilePath As String) As String
  446. If Http.MIMETypes.ContainsKey(Path.GetExtension(FilePath.ToLower).Remove(0, 1)) Then
  447. Return Http.MIMETypes.Item(Path.GetExtension(FilePath.ToLower).Remove(0, 1))
  448. End If
  449. Return "unknown/unknown"
  450. End Function
  451.  
  452. Private Function GetRedirectUrl(ByVal RequestUri As String, ByVal Redirect As String) As String
  453. Dim str2 As String = String.Empty
  454. If Http.IsValidUri(Redirect) Then
  455. Return Redirect
  456. End If
  457. If ((Redirect.StartsWith("&") Or Redirect.StartsWith("?")) Or RequestUri.EndsWith("/")) Then
  458. If (RequestUri.EndsWith("/") AndAlso Redirect.StartsWith("/")) Then
  459. Return (RequestUri & Redirect.Substring(1))
  460. End If
  461. Return (RequestUri & Redirect)
  462. End If
  463. If Redirect.StartsWith("/") Then
  464. Dim flag As Boolean = False
  465. Dim str3 As String
  466. For Each str3 In Strings.Split(Redirect, "/", -1, CompareMethod.Binary)
  467. If RequestUri.EndsWith(("/" & str3)) Then
  468. str2 = (RequestUri & Redirect.Substring(((Redirect.IndexOf(("/" & str3)) + str3.Length) + 1)))
  469. Exit For
  470. End If
  471. Next
  472. If Not flag Then
  473. str2 = (Interaction.IIf(RequestUri.StartsWith("https"), "https://", "http://").ToString & New Uri(RequestUri).Host & Redirect)
  474. End If
  475. End If
  476. Return str2
  477. End Function
  478.  
  479. Private Function GetRequestHeaders(ByVal Request As HttpWebRequest) As String
  480. Return String.Format("Request Headers -----------------------------------{0}{1}", ChrW(13) & ChrW(10), Request.Headers.ToString)
  481. End Function
  482.  
  483. Public Function GetResponse(ByVal Method As Verb, ByVal Uri As String, Optional ByVal PostData As Byte() = Nothing, Optional ByVal ExtraHeaders As NameValueCollection = Nothing) As HttpResponse
  484. Dim response3 As New HttpResponse
  485. Dim expression As Exception = Nothing
  486. Dim response As HttpWebResponse = Nothing
  487. Label_000A:
  488. Try
  489. Dim redirectUrl As String
  490. If Not Uri.StartsWith("http") Then
  491. Uri = ("http://" & Uri)
  492. End If
  493. If Not Http.IsValidUri(Uri) Then
  494. expression = New Exception(String.Format("'{0}' is not a valid Uri.", Uri))
  495. Return response3
  496. End If
  497. Dim request As HttpWebRequest = Me.SendRequest(Method, Uri, PostData, ExtraHeaders)
  498. response = DirectCast(request.GetResponse, HttpWebResponse)
  499. Me.Cookies.Add(response.Cookies)
  500. Dim response4 As HttpResponse = response3
  501. response4.WebRequest = request
  502. response4.RequestUri = request.RequestUri.ToString
  503. response4.RequestHeaders = Me.GetRequestHeaders(request)
  504. If Not Information.IsNothing(PostData) Then
  505. Dim response6 As HttpResponse = response4
  506. response6.RequestHeaders = (response6.RequestHeaders & ChrW(13) & ChrW(10) & ChrW(13) & ChrW(10) & Me.Verbs(CInt(Method)) & Encoding.UTF8.GetString(PostData))
  507. End If
  508. response4.WebResponse = response
  509. response4.ResponseUri = response.ResponseUri.ToString
  510. response4.ResponseHeaders = Me.GetResponseHeaders(response)
  511. response4 = Nothing
  512. PostData = Nothing
  513. Dim response5 As HttpWebResponse = response
  514. Select Case response5.StatusCode
  515. Case HttpStatusCode.MovedPermanently, HttpStatusCode.Found, HttpStatusCode.SeeOther, HttpStatusCode.TemporaryRedirect
  516. redirectUrl = Me.GetRedirectUrl(response3.RequestUri, response5.Headers.Item("Location"))
  517. If Not Me.AutoRedirect Then
  518. GoTo Label_01B0
  519. End If
  520. If (Not String.IsNullOrEmpty(redirectUrl) AndAlso Not Me.IsBlackListed(redirectUrl)) Then
  521. Exit Select
  522. End If
  523. GoTo Label_0234
  524. Case HttpStatusCode.OK
  525. Me.LastResponseUri = response.ResponseUri.ToString
  526. If Not Information.IsNothing(response5.Headers.Item(HttpResponseHeader.ContentType)) Then
  527. If response5.Headers.Item(HttpResponseHeader.ContentType).StartsWith("image") Then
  528. response3.Image = Image.FromStream(response5.GetResponseStream)
  529. Return response3
  530. End If
  531. If response5.Headers.Item(HttpResponseHeader.ContentType).StartsWith("video") Then
  532. Return response3
  533. End If
  534. End If
  535. GoTo Label_0234
  536. Case Else
  537. GoTo Label_0234
  538. End Select
  539. Uri = redirectUrl
  540. Method = Verb.GET
  541. Me.Referer = response3.RequestUri
  542. GoTo Label_000A
  543. Label_01B0:
  544. response3.RedirectUrl = redirectUrl
  545. Label_0234:
  546. response5 = Nothing
  547. response3.StatusCode = response.StatusCode
  548. response3.Html = Me.ProcessResponse(response)
  549. Me._LastResponseUri = Uri
  550. If Not ((response3.Html.ToLower.Contains("<meta http-equiv=""refresh") Or response3.Html.ToLower.Contains("window.parent.location.href =""")) Or response3.Html.ToLower.Contains("window.location.replace(""")) Then
  551. Return response3
  552. End If
  553. Dim str As String = String.Empty
  554. If response3.Html.ToLower.Contains("<meta http-equiv=""refresh") Then
  555. str = Me.GetRedirectUrl(response3.RequestUri, Http.ParseMetaRefreshUrl(response3.Html))
  556. ElseIf response3.Html.ToLower.Contains("window.parent.location.href =""") Then
  557. str = Me.GetRedirectUrl(response3.RequestUri, Http.ParseBetween(response3.Html, "window.parent.location.href=""", """", "window.parent.location.href=""".Length).Trim)
  558. ElseIf response3.Html.ToLower.Contains("window.location.replace(""") Then
  559. str = Me.GetRedirectUrl(response3.RequestUri, Http.ParseBetween(response3.Html, "window.location.replace(""", """", "window.location.replace(""".Length).Trim)
  560. End If
  561. If Me.AllowMetaRedirect Then
  562. If String.IsNullOrEmpty(str) Then
  563. Return response3
  564. End If
  565. If Me.IsBlackListed(str) Then
  566. response3.RedirectUrl = str
  567. Return response3
  568. End If
  569. Uri = str
  570. Method = Verb.GET
  571. Me.Referer = response3.RequestUri
  572. GoTo Label_000A
  573. End If
  574. response3.RedirectUrl = str
  575. Catch exception1 As WebException
  576. ProjectData.SetProjectError(exception1)
  577. Dim ex As WebException = exception1
  578. ProjectData.SetProjectError(ex)
  579. Dim exception3 As WebException = ex
  580. expression = exception3
  581. If Not Information.IsNothing(exception3.Response) Then
  582. response3.WebResponse = DirectCast(exception3.Response, HttpWebResponse)
  583. response3.StatusCode = response3.WebResponse.StatusCode
  584. response3.Html = Me.ProcessResponse(response3.WebResponse)
  585. End If
  586. ProjectData.ClearProjectError()
  587. ProjectData.ClearProjectError()
  588. Catch exception5 As Exception
  589. ProjectData.SetProjectError(exception5)
  590. Dim exception4 As Exception = exception5
  591. ProjectData.SetProjectError(exception4)
  592. expression = exception4
  593. ProjectData.ClearProjectError()
  594. ProjectData.ClearProjectError()
  595. Finally
  596. If Not Information.IsNothing(expression) Then
  597. response3.Error = Me.ProcessException(expression)
  598. End If
  599. If Not Information.IsNothing(response) Then
  600. response.Close()
  601. End If
  602. If response3.StatusCode.Equals(HttpStatusCode.GatewayTimeout) Then
  603. response3.TimedOut = True
  604. End If
  605. Me.Referer = String.Empty
  606. End Try
  607. Return response3
  608. End Function
  609.  
  610. Public Function GetResponse(ByVal Method As Verb, ByVal Uri As String, ByVal PostData As String, Optional ByVal ExtraHeaders As NameValueCollection = Nothing) As HttpResponse
  611. Dim postData1 As Byte() = Nothing
  612. If Not String.IsNullOrEmpty(PostData) Then
  613. postData1 = Encoding.UTF8.GetBytes(PostData)
  614. End If
  615. Return Me.GetResponse(Method, Uri, postData, ExtraHeaders)
  616. End Function
  617.  
  618. Public Function GetResponse(ByVal Method As Verb, ByVal Uri As String, ByVal ExtraHeaders As NameValueCollection, ByVal Fields As NameValueCollection, ByVal ParamArray Upload As UploadData()) As HttpResponse
  619. Dim str As String = Guid.NewGuid.ToString.Replace("-", "")
  620. Me.ContentType = ("multipart/form-data; boundary=" & str)
  621. Dim stream As New MemoryStream
  622. Dim writer As New StreamWriter(stream)
  623. If (Not Fields Is Nothing) Then
  624. Dim num2 As Integer = (Fields.Count - 1)
  625. Dim i As Integer = 0
  626. Do While (i <= num2)
  627. writer.Write(("--" & str & ChrW(13) & ChrW(10)))
  628. writer.Write("Content-Disposition: form-data; name=""{0}""{1}{1}{2}{1}", Fields.Keys.Item(i), ChrW(13) & ChrW(10), Fields.Item(i))
  629. i += 1
  630. Loop
  631. End If
  632. If Not Information.IsNothing(Upload) Then
  633. Dim data As UploadData
  634. For Each data In Upload
  635. writer.Write(("--" & str & ChrW(13) & ChrW(10)))
  636. writer.Write("Content-Disposition: form-data; name=""{0}""; filename=""{1}""{2}", data.FieldName, data.FileName, ChrW(13) & ChrW(10))
  637. writer.Write(("Content-Type: " & data.ContentType & ChrW(13) & ChrW(10) & ChrW(13) & ChrW(10)))
  638. writer.Flush()
  639. If Not Information.IsNothing(data.Contents) Then
  640. stream.Write(data.Contents, 0, data.Contents.Length)
  641. End If
  642. writer.Write(ChrW(13) & ChrW(10))
  643. Next
  644. End If
  645. writer.Write("--{0}--{1}", str, ChrW(13) & ChrW(10))
  646. writer.Flush()
  647. writer = Nothing
  648. Me.ContentType = ("multipart/form-data; boundary=" & str)
  649. Dim response2 As HttpResponse = Me.GetResponse(Method, Uri, stream.ToArray, ExtraHeaders)
  650. Me.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"
  651. Return response2
  652. End Function
  653.  
  654. Public Function GetResponse(ByVal Method As Verb, ByVal Uri As String, ByVal ContType As String, ByVal Boundary As String, ByVal ExtraHeaders As NameValueCollection, ByVal Fields As NameValueCollection, ByVal ParamArray Upload As UploadData()) As HttpResponse
  655. Me.ContentType = ContType
  656. Dim stream As New MemoryStream
  657. Dim writer As New StreamWriter(stream)
  658. If (Not Fields Is Nothing) Then
  659. Dim num2 As Integer = (Fields.Count - 1)
  660. Dim i As Integer = 0
  661. Do While (i <= num2)
  662. writer.Write(("--" & Boundary & ChrW(13) & ChrW(10)))
  663. writer.Write("Content-Disposition: form-data; name=""{0}""{1}{1}{2}{1}", Fields.Keys.Item(i), ChrW(13) & ChrW(10), Fields.Item(i))
  664. i += 1
  665. Loop
  666. End If
  667. If Not Information.IsNothing(Upload) Then
  668. Dim data As UploadData
  669. For Each data In Upload
  670. writer.Write(("--" & Boundary & ChrW(13) & ChrW(10)))
  671. writer.Write("Content-Disposition: form-data; name=""{0}""; filename=""{1}""{2}", data.FieldName, data.FileName, ChrW(13) & ChrW(10))
  672. writer.Write(("Content-Type: " & data.ContentType & ChrW(13) & ChrW(10) & ChrW(13) & ChrW(10)))
  673. writer.Flush()
  674. If Not Information.IsNothing(data.Contents) Then
  675. stream.Write(data.Contents, 0, data.Contents.Length)
  676. End If
  677. writer.Write(ChrW(13) & ChrW(10))
  678. Next
  679. End If
  680. writer.Write("--{0}--{1}", Boundary, ChrW(13) & ChrW(10))
  681. writer.Flush()
  682. writer = Nothing
  683. Me.ContentType = ContType
  684. Dim response2 As HttpResponse = Me.GetResponse(Method, Uri, stream.ToArray, ExtraHeaders)
  685. Me.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"
  686. Return response2
  687. End Function
  688.  
  689. Private Function GetResponseHeaders(ByVal Response As HttpWebResponse) As String
  690. Return String.Format("Response Headers -----------------------------------{0}{1}{0}{2}", ChrW(13) & ChrW(10), ("StatusCode: " & Conversions.ToString(CInt(Response.StatusCode)) & " " & Response.StatusDescription), Response.Headers.ToString)
  691. End Function
  692.  
  693. Public Shared Function GetTimeStamp(ByVal Value As DateTime) As Long
  694. Return Convert.ToInt64(Value.Subtract(Convert.ToDateTime("1.1.1970 00:00:00")).TotalMilliseconds)
  695. End Function
  696.  
  697. Public Shared Function ImageToBase64(ByVal Image As Image, ByVal Format As ImageFormat) As String
  698. Dim str2 As String = String.Empty
  699. Try
  700. Using stream As MemoryStream = New MemoryStream
  701. Image.Save(stream, Format)
  702. Return Convert.ToBase64String(stream.ToArray)
  703. End Using
  704. Catch exception1 As Exception
  705. ProjectData.SetProjectError(exception1)
  706. Dim ex As Exception = exception1
  707. ProjectData.SetProjectError(ex)
  708. ProjectData.ClearProjectError()
  709. ProjectData.ClearProjectError()
  710. End Try
  711. Return str2
  712. End Function
  713.  
  714. Public Shared Function ImageToBytes(ByVal Image As Image) As Byte()
  715. Using stream As MemoryStream = New MemoryStream
  716. Image.Save(stream, ImageFormat.Jpeg)
  717. stream.Close()
  718. Return stream.ToArray
  719. End Using
  720. End Function
  721.  
  722. Private Function IsBlackListed(ByVal Url As String) As Boolean
  723. Dim str As String
  724. For Each str In Me.RedirectBlacklist
  725. If Url.ToLower.Contains(str.ToLower) Then
  726. Return True
  727. End If
  728. Next
  729. Return False
  730. End Function
  731.  
  732. Public Shared Function IsValidIP(ByVal IP As String) As Boolean
  733. Return Regex.IsMatch(IP, "^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$")
  734. End Function
  735.  
  736. Public Shared Function IsValidProxy(ByVal proxy As String) As Boolean
  737. Dim pattern As String = "[0-9]{1,3}\.[0-9}{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,4}"
  738. Dim regex As New Regex(pattern)
  739. Return regex.Match(proxy).Success
  740. End Function
  741.  
  742. Public Shared Function IsValidUri(ByVal Url As String) As Boolean
  743. Return Regex.IsMatch(Url, "^(http)(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&=:%\$#_]*)?")
  744. End Function
  745.  
  746. Public Function MakeProxy(ByVal proxy As String) As HttpProxy
  747. Dim proxy3 As HttpProxy
  748. If Http.IsValidProxy(proxy) Then
  749. Try
  750. Dim proxy4 As New HttpProxy
  751. proxy4.Server = Strings.Split(proxy, ":", -1, CompareMethod.Binary)(0)
  752. proxy4.Port = Conversions.ToInteger(Strings.Split(proxy, ":", -1, CompareMethod.Binary)(1))
  753. If (Http.CountOccurance(proxy, ":", False) = 3) Then
  754. proxy4.UserName = Strings.Split(proxy, ":", -1, CompareMethod.Binary)(2)
  755. proxy4.Password = Strings.Split(proxy, ":", -1, CompareMethod.Binary)(3)
  756. End If
  757. Return proxy4
  758. Catch exception1 As Exception
  759. ProjectData.SetProjectError(exception1)
  760. Dim ex As Exception = exception1
  761. ProjectData.SetProjectError(ex)
  762. Dim exception As Exception = ex
  763. ProjectData.ClearProjectError()
  764. ProjectData.ClearProjectError()
  765. End Try
  766. End If
  767. Return proxy3
  768. End Function
  769.  
  770. Public Shared Function ParseBetween(ByVal Html As String, ByVal Before As String, ByVal After As String, ByVal Offset As Integer) As String
  771. If (String.IsNullOrEmpty(Html) OrElse Not Html.Contains(Before)) Then
  772. Return String.Empty
  773. End If
  774. Dim str2 As String = Html.Substring((Html.IndexOf(Before) + Offset))
  775. If (str2.Contains(After) AndAlso Not String.IsNullOrEmpty(After)) Then
  776. str2 = str2.Substring(0, str2.IndexOf(After))
  777. End If
  778. Return str2
  779. End Function
  780.  
  781. Public Shared Function ParseBetweenAll(ByVal Html As String, ByVal Before As String, ByVal After As String) As String()
  782. Dim list As New List(Of String)
  783. Dim list2 As New List(Of String)
  784. Dim list3 As List(Of String) = list2
  785. list3.AddRange(Regex.Split(Html, Before))
  786. list3.RemoveAt(0)
  787. Dim str As String
  788. For Each str In list2
  789. list.Add(Regex.Split(str, After)(0))
  790. Next
  791. list3 = Nothing
  792. Return list.ToArray
  793. End Function
  794.  
  795. Private Sub ParseCookie(ByVal Data As String, ByVal Uri As Uri)
  796. Dim item As New HttpCookie
  797. Dim cookie As HttpCookie = item
  798. cookie.Name = Data.Split(New Char() {Convert.ToChar("=")})(0).Trim
  799. If Not Me.CookieBlacklist.Contains(cookie.Name) Then
  800. cookie.HttpOnly = False
  801. cookie.Secure = False
  802. If Data.Contains(";") Then
  803. cookie.Value = Data.Substring(0, Data.IndexOf(";"))
  804. cookie.Value = cookie.Value.Split(New Char() {Convert.ToChar("=")})(1).Trim
  805. Else
  806. cookie.Value = Data.Split(New Char() {Convert.ToChar("=")})(1).Trim
  807. End If
  808. If cookie.Value.ToLower.Equals("deleted") Then
  809. Dim expression As HttpCookie = Me.FindCookie(cookie.Name)
  810. If Not Information.IsNothing(expression) Then
  811. Me.RemoveCookie(expression)
  812. End If
  813. Else
  814. Dim str As String
  815. For Each str In Strings.Split(Data, ";", -1, CompareMethod.Binary)
  816. str = str.Trim
  817. If Not String.IsNullOrEmpty(str) Then
  818. If str.Contains("=") Then
  819. Dim str2 As String = str.Split(New Char() {Convert.ToChar("=")})(0).Trim
  820. Dim str3 As String = str.Substring((str.IndexOf("=") + 1)).Trim
  821. Dim str4 As String = str2.ToLower
  822. If (str4 = cookie.Name.ToLower) Then
  823. cookie.Value = str3
  824. ElseIf (str4 = "path") Then
  825. cookie.Path = str3
  826. ElseIf (str4 = "expires") Then
  827. str3 = Me.TrimDay(str3)
  828. If (str3.ToLower.EndsWith("utc") Or str3.ToLower.EndsWith("gmt")) Then
  829. str3 = str3.Substring(0, str3.ToLower.IndexOf(Interaction.IIf(str3.ToLower.EndsWith("utc"), "utc", "gmt").ToString)).Trim
  830. End If
  831. Try
  832. cookie.Expires = DateTime.Parse(str3)
  833. Catch exception1 As Exception
  834. ProjectData.SetProjectError(exception1)
  835. Dim ex As Exception = exception1
  836. ProjectData.SetProjectError(ex)
  837. cookie.Expires = DateAndTime.Now.AddDays(3)
  838. ProjectData.ClearProjectError()
  839. ProjectData.ClearProjectError()
  840. End Try
  841. ElseIf (str4 = "domain") Then
  842. cookie.Domain = str3
  843. ElseIf (str4 = "httponly") Then
  844. cookie.HttpOnly = True
  845. ElseIf (str4 = "secure") Then
  846. cookie.Secure = True
  847. ElseIf (str4 = "version") Then
  848. cookie.Version = Convert.ToInt32(str3)
  849. ElseIf (str4 = "max-age") Then
  850. End If
  851. Else
  852. Select Case str.ToLower
  853. Case "secure"
  854. cookie.Secure = True
  855. Exit Select
  856. Case "httponly"
  857. cookie.HttpOnly = True
  858. Exit Select
  859. End Select
  860. End If
  861. End If
  862. Next
  863. If String.IsNullOrEmpty(cookie.Path) Then
  864. cookie.Path = Uri.AbsolutePath
  865. End If
  866. If String.IsNullOrEmpty(cookie.Domain) Then
  867. cookie.Domain = Uri.Host
  868. End If
  869. If cookie.Domain.StartsWith("www.") Then
  870. cookie.Domain = Strings.Replace(cookie.Domain, "www.", ".", 1, -1, CompareMethod.Binary)
  871. End If
  872. If Not String.IsNullOrEmpty(cookie.Value) Then
  873. Dim cookie4 As HttpCookie = Me.FindCookie(cookie.Name)
  874. If Not Information.IsNothing(cookie4) Then
  875. Me.RemoveCookie(cookie4)
  876. End If
  877. Me.SessionCookies.Add(item)
  878. End If
  879. End If
  880. cookie = Nothing
  881. End If
  882. End Sub
  883.  
  884. Public Shared Function ParseFormClassText(ByVal Html As String, ByVal ClassName As String, Optional ByVal Highlighter As String = """") As String
  885. If String.IsNullOrEmpty(Html) Then
  886. Return String.Empty
  887. End If
  888. Dim str2 As String = String.Empty
  889. Try
  890. Html = Html.Substring((Html.IndexOf(("class=" & Highlighter & ClassName & Highlighter)) + 7))
  891. str2 = Http.ParseBetween(Html, ("value=" & Highlighter), Highlighter, 7)
  892. Catch exception1 As Exception
  893. ProjectData.SetProjectError(exception1)
  894. Dim ex As Exception = exception1
  895. ProjectData.SetProjectError(ex)
  896. ProjectData.ClearProjectError()
  897. ProjectData.ClearProjectError()
  898. End Try
  899. Return str2
  900. End Function
  901.  
  902. Public Shared Function ParseFormIdText(ByVal Html As String, ByVal Id As String, Optional ByVal Highlighter As String = """") As String
  903. If String.IsNullOrEmpty(Html) Then
  904. Return String.Empty
  905. End If
  906. Dim str2 As String = String.Empty
  907. Try
  908. Html = Html.Substring((Html.IndexOf(("id=" & Highlighter & Id & Highlighter)) + 5))
  909. str2 = Http.ParseBetween(Html, ("value=" & Highlighter), Highlighter, 7)
  910. Catch exception1 As Exception
  911. ProjectData.SetProjectError(exception1)
  912. Dim ex As Exception = exception1
  913. ProjectData.SetProjectError(ex)
  914. ProjectData.ClearProjectError()
  915. ProjectData.ClearProjectError()
  916. End Try
  917. Return str2
  918. End Function
  919.  
  920. Public Shared Function ParseFormNameText(ByVal Html As String, ByVal Name As String, Optional ByVal Highlighter As String = """") As String
  921. If String.IsNullOrEmpty(Html) Then
  922. Return String.Empty
  923. End If
  924. Dim str2 As String = String.Empty
  925. Try
  926. Html = Html.Substring((Html.IndexOf(("name=" & Highlighter & Name & Highlighter)) + 5))
  927. str2 = Http.ParseBetween(Html, ("value=" & Highlighter), Highlighter, 7)
  928. Catch exception1 As Exception
  929. ProjectData.SetProjectError(exception1)
  930. Dim ex As Exception = exception1
  931. ProjectData.SetProjectError(ex)
  932. ProjectData.ClearProjectError()
  933. ProjectData.ClearProjectError()
  934. End Try
  935. Return str2
  936. End Function
  937.  
  938. Public Shared Function ParseMetaRefreshUrl(ByVal Html As String) As String
  939. If String.IsNullOrEmpty(Html) Then
  940. Return String.Empty
  941. End If
  942. Dim str2 As String = Html.ToLower
  943. Dim str3 As String = Http.ParseBetween(Html.Substring((str2.IndexOf("<meta http-equiv=""refresh""") + "<meta http-equiv=""refresh""".Length)), "url=", """", "url=".Length).Trim
  944. If str3.StartsWith("'") Then
  945. str3 = str3.Substring(1)
  946. End If
  947. If str3.EndsWith("'") Then
  948. str3 = str3.Substring(0, (str3.Length - 1))
  949. End If
  950. Return str3
  951. End Function
  952.  
  953. Private Sub ProcessCookies(ByVal Response As HttpWebResponse)
  954. Try
  955. If Information.IsNothing(Me.SessionCookies) Then
  956. Me.SessionCookies = New List(Of HttpCookie)
  957. End If
  958. Dim str As String = Response.Headers.Item("Set-Cookie")
  959. If (Not String.IsNullOrEmpty(str) AndAlso Not String.IsNullOrEmpty(str)) Then
  960. str = str.Replace("Mon,", "Mon").Replace("Tue,", "Tue").Replace("Wed,", "Wed").Replace("Thu,", "Thu").Replace("Fri,", "Fri").Replace("Sat,", "Sat").Replace("Sun,", "Sun").Replace("Monday,", "Mon").Replace("Tuesday,", "Tue").Replace("Wednesday,", "Wed").Replace("Thursday,", "Thurs").Replace("Friday,", "Fri").Replace("Saturday,", "Sat").Replace("Sunday,", "Sun")
  961. If Not str.Contains(",") Then
  962. Me.ParseCookie(str, Response.ResponseUri)
  963. Else
  964. Dim str2 As String
  965. For Each str2 In str.Split(New Char() {Convert.ToChar(",")})
  966. Me.ParseCookie(str2, Response.ResponseUri)
  967. Next
  968. End If
  969. End If
  970. Catch exception1 As Exception
  971. ProjectData.SetProjectError(exception1)
  972. Dim ex As Exception = exception1
  973. ProjectData.SetProjectError(ex)
  974. ProjectData.ClearProjectError()
  975. ProjectData.ClearProjectError()
  976. End Try
  977. End Sub
  978.  
  979. Private Function ProcessException(ByVal Ex As Object) As HttpError
  980. Dim [error] As New HttpError
  981. Dim message As String = String.Empty
  982. [error].Exception = RuntimeHelpers.GetObjectValue(RuntimeHelpers.GetObjectValue(RuntimeHelpers.GetObjectValue(Ex)))
  983. If TypeOf Ex Is WebException Then
  984. Dim exception As WebException = DirectCast(Ex, WebException)
  985. If (Not Information.IsNothing(exception.Response) AndAlso DirectCast(exception.Response, HttpWebResponse).StatusCode.Equals(HttpStatusCode.BadGateway)) Then
  986. message = exception.Message
  987. If Not String.IsNullOrEmpty(Me.Proxy.Server) Then
  988. [error].IsProxyError = True
  989. End If
  990. End If
  991. If exception.Message.Contains("The underlying connection was closed:") Then
  992. message = exception.Message
  993. If Not String.IsNullOrEmpty(Me.Proxy.Server) Then
  994. [error].IsProxyError = True
  995. End If
  996. ElseIf exception.Message.Contains("The remote server returned an error: (") Then
  997. message = exception.Message
  998. If Not String.IsNullOrEmpty(Me.Proxy.Server) Then
  999. [error].IsProxyError = True
  1000. End If
  1001. Else
  1002. Select Case exception.Status
  1003. Case WebExceptionStatus.ConnectFailure
  1004. If exception.Message.Trim.Equals("Unable to connect to the remote server") Then
  1005. message = Interaction.IIf(Not String.IsNullOrEmpty(Me.Proxy.Server), "Could not connect to proxy server.", "Could not connect to server.").ToString
  1006. If Not String.IsNullOrEmpty(Me.Proxy.Server) Then
  1007. [error].IsProxyError = True
  1008. End If
  1009. Else
  1010. message = exception.Message
  1011. End If
  1012. GoTo Label_0244
  1013. Case WebExceptionStatus.KeepAliveFailure
  1014. message = Interaction.IIf(Not String.IsNullOrEmpty(Me.Proxy.Server), "Disconnected from proxy server.", exception.Message).ToString
  1015. If Not String.IsNullOrEmpty(Me.Proxy.Server) Then
  1016. [error].IsProxyError = True
  1017. End If
  1018. GoTo Label_0244
  1019. Case WebExceptionStatus.Timeout
  1020. message = "Timed out."
  1021. If Not String.IsNullOrEmpty(Me.Proxy.Server) Then
  1022. [error].IsProxyError = True
  1023. End If
  1024. GoTo Label_0244
  1025. End Select
  1026. message = exception.Message
  1027. End If
  1028. Else
  1029. message = TryCast(Ex, Exception).Message
  1030. End If
  1031. Label_0244:
  1032. [error].Message = message
  1033. Return [error]
  1034. End Function
  1035.  
  1036. Private Function ProcessResponse(ByVal Response As HttpWebResponse) As String
  1037. Dim str2 As String
  1038. Try
  1039. Dim builder As New StringBuilder
  1040. Dim responseStream As Stream = Response.GetResponseStream
  1041. If Response.ContentEncoding.ToLower.Contains("gzip") Then
  1042. responseStream = New GZipStream(responseStream, CompressionMode.Decompress)
  1043. ElseIf Response.ContentEncoding.ToLower.Contains("deflate") Then
  1044. responseStream = New DeflateStream(responseStream, CompressionMode.Decompress)
  1045. End If
  1046. Using reader As StreamReader = New StreamReader(responseStream)
  1047. Dim buffer As Char() = New Char(&H401 - 1) {}
  1048. Dim i As Integer = reader.Read(buffer, 0, &H400)
  1049. Do While (i > 0)
  1050. Dim expression As New String(buffer, 0, i)
  1051. expression = Strings.Replace(expression, ChrW(0), String.Empty, 1, -1, CompareMethod.Binary)
  1052. builder.Append(expression)
  1053. i = reader.Read(buffer, 0, &H400)
  1054. Loop
  1055. reader.Close()
  1056. End Using
  1057. responseStream.Close()
  1058. responseStream.Dispose()
  1059. responseStream = Nothing
  1060. str2 = builder.ToString
  1061. Catch exception1 As Exception
  1062. ProjectData.SetProjectError(exception1)
  1063. Dim ex As Exception = exception1
  1064. ProjectData.SetProjectError(ex)
  1065. Dim exception As Exception = ex
  1066. str2 = String.Empty
  1067. ProjectData.ClearProjectError()
  1068. Dim str As String = str2
  1069. ProjectData.ClearProjectError()
  1070. Return str
  1071. End Try
  1072. Return str2
  1073. End Function
  1074.  
  1075. Public Sub RemoveCookie(ByVal Name As String)
  1076. Dim expression As HttpCookie = Me.FindCookie(Name)
  1077. If Not Information.IsNothing(expression) Then
  1078. Me.RemoveCookie(expression)
  1079. End If
  1080. End Sub
  1081.  
  1082. Public Sub RemoveCookie(ByVal c As HttpCookie)
  1083. Me.SessionCookies.Remove(c)
  1084. End Sub
  1085.  
  1086. Public Sub RemoveCookie(ByVal Name As String, ByVal Domain As String)
  1087. Dim index As Integer = (Me.SessionCookies.Count - 1)
  1088. Do While True
  1089. Dim num2 As Integer = 0
  1090. If (index < num2) Then
  1091. Return
  1092. End If
  1093. Dim cookie As HttpCookie = Me.SessionCookies.Item(index)
  1094. If ((cookie.Name = Name) AndAlso (cookie.Domain = Domain)) Then
  1095. Me.SessionCookies.RemoveAt(index)
  1096. End If
  1097. index = (index + -1)
  1098. Loop
  1099. End Sub
  1100.  
  1101. Public Shared Function ResolveHost(ByVal Host As String) As IPAddress()
  1102. Dim addressList As IPAddress()
  1103. Try
  1104. addressList = Dns.GetHostEntry(Host).AddressList
  1105. Catch exception1 As Exception
  1106. ProjectData.SetProjectError(exception1)
  1107. Dim ex As Exception = exception1
  1108. ProjectData.SetProjectError(ex)
  1109. Dim exception As Exception = ex
  1110. addressList = Nothing
  1111. ProjectData.ClearProjectError()
  1112. Dim addressArray2 As IPAddress() = addressList
  1113. ProjectData.ClearProjectError()
  1114. Return addressArray2
  1115. End Try
  1116. Return addressList
  1117. End Function
  1118.  
  1119. Public Shared Function ResolveIP(ByRef IP As String) As String
  1120. Dim hostName As String
  1121. Try
  1122. hostName = Dns.GetHostEntry(IP).HostName
  1123. Catch exception1 As Exception
  1124. ProjectData.SetProjectError(exception1)
  1125. Dim ex As Exception = exception1
  1126. ProjectData.SetProjectError(ex)
  1127. Dim exception As Exception = ex
  1128. hostName = String.Empty
  1129. ProjectData.ClearProjectError()
  1130. Dim str2 As String = hostName
  1131. ProjectData.ClearProjectError()
  1132. Return str2
  1133. End Try
  1134. Return hostName
  1135. End Function
  1136.  
  1137. Private Function SendRequest(ByVal Method As Verb, ByVal Uri As String, ByVal PostData As Byte(), ByVal ExtraHeaders As NameValueCollection) As HttpWebRequest
  1138. If Information.IsNothing(ExtraHeaders) Then
  1139. ExtraHeaders = New NameValueCollection
  1140. End If
  1141. Dim flag As Boolean = Uri.ToLower.StartsWith("https://")
  1142. Dim request As HttpWebRequest = DirectCast(WebRequest.Create(Uri), HttpWebRequest)
  1143. Dim request2 As HttpWebRequest = request
  1144. request2.AllowWriteStreamBuffering = Me.AllowWriteStreamBuffering
  1145. request2.AllowAutoRedirect = False
  1146. request2.AutomaticDecompression = DecompressionMethods.None
  1147. request2.ProtocolVersion = Me.Version
  1148. request2.ServicePoint.Expect100Continue = Me.AllowExpect100
  1149. request2.Timeout = Me.TimeOut
  1150. request2.ServicePoint.GetType.GetProperty("HttpBehaviour", (BindingFlags.NonPublic Or BindingFlags.Instance)).SetValue(request2.ServicePoint, CByte(0), Nothing)
  1151. If Not String.IsNullOrEmpty(Me.Proxy.Server) Then
  1152. request2.Proxy = New WebProxy(Me.Proxy.Server, Me.Proxy.Port)
  1153. If Not String.IsNullOrEmpty(Me.Proxy.UserName) Then
  1154. request2.Proxy.Credentials = New NetworkCredential(Me.Proxy.UserName, Me.Proxy.Password)
  1155. End If
  1156. End If
  1157. Dim debugMode As Boolean = Me.DebugMode
  1158. request2.Method = Me.Verbs(CInt(Method))
  1159. request2.Headers.Clear()
  1160. request2.KeepAlive = Me.KeepAlive
  1161. Dim headers As New WebHeaderCollection
  1162. Dim headers2 As WebHeaderCollection = headers
  1163. headers2.Add(HttpRequestHeader.Host, New Uri(Uri).Host)
  1164. headers2.Add(HttpRequestHeader.UserAgent, Me.Useragent)
  1165. If Not String.IsNullOrEmpty(Me.Accept) Then
  1166. headers2.Add(HttpRequestHeader.Accept, Me.Accept)
  1167. End If
  1168. If Not String.IsNullOrEmpty(Me.AcceptLanguage) Then
  1169. headers2.Add(HttpRequestHeader.AcceptLanguage, Me.AcceptLanguage)
  1170. End If
  1171. If Not String.IsNullOrEmpty(Me.AcceptEncoding) Then
  1172. headers2.Add(HttpRequestHeader.AcceptEncoding, Me.AcceptEncoding)
  1173. End If
  1174. If Not String.IsNullOrEmpty(Me.AcceptCharset) Then
  1175. headers2.Add(HttpRequestHeader.AcceptCharset, Me.AcceptCharset)
  1176. End If
  1177. If (ExtraHeaders.Count <> 0) Then
  1178. Dim num4 As Integer = (ExtraHeaders.Count - 1)
  1179. Dim j As Integer = 0
  1180. Do While (j <= num4)
  1181. Dim str As String = ExtraHeaders.Keys.Item(j)
  1182. If (If(((((str = "Host") OrElse (str = "User-Agent")) OrElse ((str = "Referer") OrElse (str = "Accept"))) OrElse (((str = "Accept-Language") OrElse (str = "Accept-Charset")) OrElse (str = "Connection"))), 1, 0) = 0) Then
  1183. headers2.Add(ExtraHeaders.Keys.Item(j), ExtraHeaders.Item(j))
  1184. End If
  1185. j += 1
  1186. Loop
  1187. End If
  1188. If Not String.IsNullOrEmpty(Me.Referer) Then
  1189. headers2.Add(HttpRequestHeader.Referer, Me.Referer)
  1190. End If
  1191. headers2 = Nothing
  1192. Dim num2 As Integer = (headers.Count - 1)
  1193. Dim i As Integer = 0
  1194. Do While (i <= num2)
  1195. Dim type As Type = GetType(WebHeaderCollection)
  1196. type.GetMethod("AddWithoutValidate", (BindingFlags.NonPublic Or BindingFlags.Instance)).Invoke(request.Headers, New Object() {headers.Keys.Item(i), headers.Item(i)})
  1197. i += 1
  1198. Loop
  1199. If Not Information.IsNothing(PostData) Then
  1200. request2.SendChunked = Me.SendChunked
  1201. request2.ContentType = Me.ContentType
  1202. request2.ContentLength = PostData.Length
  1203. Dim requestStream As Stream = request2.GetRequestStream
  1204. requestStream.Write(PostData, 0, PostData.Length)
  1205. requestStream.Close()
  1206. requestStream.Dispose()
  1207. requestStream = Nothing
  1208. End If
  1209. request2 = Nothing
  1210. PostData = Nothing
  1211. Me.LastRequestUri = Uri
  1212. Return request
  1213. End Function
  1214.  
  1215. Private Sub SetUnsafeHeaderParsing(ByVal Allow As Boolean)
  1216. Dim section As New SettingsSection
  1217. Dim type As Type = Assembly.GetAssembly(section.GetType).GetType("System.Net.Configuration.SettingsSectionInternal")
  1218. Dim args As Object() = Nothing
  1219. Dim objectValue As Object = RuntimeHelpers.GetObjectValue(RuntimeHelpers.GetObjectValue(RuntimeHelpers.GetObjectValue(type.InvokeMember("Section", (BindingFlags.GetProperty Or (BindingFlags.NonPublic Or BindingFlags.Static)), Nothing, Nothing, args))))
  1220. type.GetField("useUnsafeHeaderParsing", (BindingFlags.NonPublic Or BindingFlags.Instance)).SetValue(RuntimeHelpers.GetObjectValue(RuntimeHelpers.GetObjectValue(RuntimeHelpers.GetObjectValue(objectValue))), Allow)
  1221. End Sub
  1222.  
  1223. Public Shared Function TimeStamp() As String
  1224. Return Convert.ToInt32(DateAndTime.Now.Subtract(Convert.ToDateTime("1.1.1970 00:00:00")).TotalSeconds).ToString
  1225. End Function
  1226.  
  1227. Public Shared Function TimeStampLong() As String
  1228. Return Convert.ToInt64(DateAndTime.Now.Subtract(Convert.ToDateTime("1.1.1970 00:00:00")).TotalMilliseconds).ToString
  1229. End Function
  1230.  
  1231. Private Function TrimDay(ByVal Value As String) As String
  1232. Dim strArray As String() = New String() {"Mon", "Monday", "Tue", "Tues", "Tuesday", "Wed", "Wednesday", "Thu", "Thur", "Thurs", "Thursday", "Fri", "Friday", "Sat", "Saturday", "Sun", "Sunday"}
  1233. Dim str As String
  1234. For Each str In strArray
  1235. If Value.ToLower.Contains(str.ToLower) Then
  1236. Value = Value.ToLower.Replace(str.ToLower, String.Empty).Trim
  1237. End If
  1238. Next
  1239. Return Value
  1240. End Function
  1241.  
  1242. Public Function TrimHtml(ByVal Data As String) As String
  1243. Return Interaction.IIf(String.IsNullOrEmpty(Data), String.Empty, Regex.Replace(Data, "<.*?>", "")).ToString
  1244. End Function
  1245.  
  1246. Public Shared Function UrlEncode2(ByVal Value As String) As String
  1247. Dim str As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~"
  1248. Dim builder As New StringBuilder
  1249. Dim str2 As String = Value
  1250. Dim num2 As Integer = 0
  1251. Dim length As Integer = str2.Length
  1252. Do While (num2 < length)
  1253. Dim truePart As Char = str2.Chars(num2)
  1254. builder.Append(RuntimeHelpers.GetObjectValue(RuntimeHelpers.GetObjectValue(RuntimeHelpers.GetObjectValue(Interaction.IIf((str.IndexOf(truePart) <> -1), truePart, ("%" & String.Format("{0:X2}", Convert.ToInt32(truePart))))))))
  1255. num2 += 1
  1256. Loop
  1257. Return builder.ToString
  1258. End Function
  1259.  
  1260.  
  1261. ' Properties
  1262. Public Property Accept As String
  1263. Get
  1264. Return Me._Accept
  1265. End Get
  1266. Set(ByVal value As String)
  1267. Me._Accept = value
  1268. End Set
  1269. End Property
  1270.  
  1271. Public Property AcceptCharset As String
  1272. Get
  1273. Return Me._AcceptCharset
  1274. End Get
  1275. Set(ByVal value As String)
  1276. Me._AcceptCharset = value
  1277. End Set
  1278. End Property
  1279.  
  1280. Public Property AcceptEncoding As String
  1281. Get
  1282. Return Me._AcceptEncoding
  1283. End Get
  1284. Set(ByVal value As String)
  1285. Me._AcceptEncoding = value
  1286. End Set
  1287. End Property
  1288.  
  1289. Public Property AcceptLanguage As String
  1290. Get
  1291. Return Me._AcceptLanguage
  1292. End Get
  1293. Set(ByVal value As String)
  1294. Me._AcceptLanguage = value
  1295. End Set
  1296. End Property
  1297.  
  1298. Public Property AllowExpect100 As Boolean
  1299. Get
  1300. Return Me._AllowExpect100
  1301. End Get
  1302. Set(ByVal value As Boolean)
  1303. Me._AllowExpect100 = value
  1304. End Set
  1305. End Property
  1306.  
  1307. Public Property AllowMetaRedirect As Boolean
  1308. Get
  1309. Return Me._AllowMetaRedirect
  1310. End Get
  1311. Set(ByVal value As Boolean)
  1312. Me._AllowMetaRedirect = value
  1313. End Set
  1314. End Property
  1315.  
  1316. Public Property AllowWriteStreamBuffering As Boolean
  1317. Get
  1318. Return Me._AllowWriteStreamBuffering
  1319. End Get
  1320. Set(ByVal value As Boolean)
  1321. Me._AllowWriteStreamBuffering = value
  1322. End Set
  1323. End Property
  1324.  
  1325. Public Property AutoRedirect As Boolean
  1326. Get
  1327. Return Me._AutoRedirect
  1328. End Get
  1329. Set(ByVal value As Boolean)
  1330. Me._AutoRedirect = value
  1331. End Set
  1332. End Property
  1333.  
  1334. Public Property ContentType As String
  1335. Get
  1336. Return Me._ContentType
  1337. End Get
  1338. Set(ByVal value As String)
  1339. Me._ContentType = value
  1340. End Set
  1341. End Property
  1342.  
  1343. Public Property CustomCookies As HttpCookie()
  1344. Get
  1345. Return Me._CustomCookies
  1346. End Get
  1347. Set(ByVal value As HttpCookie())
  1348. Me._CustomCookies = value
  1349. End Set
  1350. End Property
  1351.  
  1352. Public Property DebugMode As Boolean
  1353. Get
  1354. Return Me._DebugMode
  1355. End Get
  1356. Set(ByVal value As Boolean)
  1357. Me._DebugMode = value
  1358. End Set
  1359. End Property
  1360.  
  1361. Public Property KeepAlive As Boolean
  1362. Get
  1363. Return Me._KeepAlive
  1364. End Get
  1365. Set(ByVal value As Boolean)
  1366. Me._KeepAlive = value
  1367. End Set
  1368. End Property
  1369.  
  1370. Public Property LastRequestUri As String
  1371. Get
  1372. Return Me._LastRequestUri
  1373. End Get
  1374. Set(ByVal value As String)
  1375. Me._LastRequestUri = value
  1376. End Set
  1377. End Property
  1378.  
  1379. Public Property LastResponseUri As String
  1380. Get
  1381. Return Me._LastResponseUri
  1382. End Get
  1383. Set(ByVal value As String)
  1384. Me._LastResponseUri = value
  1385. End Set
  1386. End Property
  1387.  
  1388. Public Property Proxy As HttpProxy
  1389. Get
  1390. Return Me._Proxy
  1391. End Get
  1392. Set(ByVal value As HttpProxy)
  1393. Me._Proxy = value
  1394. End Set
  1395. End Property
  1396.  
  1397. Public Property Referer As String
  1398. Get
  1399. Return Me._Referer
  1400. End Get
  1401. Set(ByVal value As String)
  1402. Me._Referer = value
  1403. End Set
  1404. End Property
  1405.  
  1406. Public Property SendChunked As Boolean
  1407. Get
  1408. Return Me._SendChunked
  1409. End Get
  1410. Set(ByVal value As Boolean)
  1411. Me._SendChunked = value
  1412. End Set
  1413. End Property
  1414.  
  1415. Public Property SendCookies As Boolean
  1416. Get
  1417. Return Me._SendCookies
  1418. End Get
  1419. Set(ByVal value As Boolean)
  1420. Me._SendCookies = value
  1421. End Set
  1422. End Property
  1423.  
  1424. Public Property StoreCookies As Boolean
  1425. Get
  1426. Return Me._StoreCookies
  1427. End Get
  1428. Set(ByVal value As Boolean)
  1429. Me._StoreCookies = value
  1430. End Set
  1431. End Property
  1432.  
  1433. Public Property TimeOut As Integer
  1434. Get
  1435. Return Me._TimeOut
  1436. End Get
  1437. Set(ByVal value As Integer)
  1438. Me._TimeOut = value
  1439. End Set
  1440. End Property
  1441.  
  1442. Public Property UseCustomCookies As Boolean
  1443. Get
  1444. Return Me._UseCustomCookies
  1445. End Get
  1446. Set(ByVal value As Boolean)
  1447. Me._UseCustomCookies = value
  1448. End Set
  1449. End Property
  1450.  
  1451. Public Property Useragent As String
  1452. Get
  1453. Return Me._UserAgent
  1454. End Get
  1455. Set(ByVal value As String)
  1456. Me._UserAgent = value
  1457. End Set
  1458. End Property
  1459.  
  1460. Public Property Version As Version
  1461. Get
  1462. Return Me._Version
  1463. End Get
  1464. Set(ByVal value As Version)
  1465. Me._Version = value
  1466. End Set
  1467. End Property
  1468.  
  1469.  
  1470. ' Fields
  1471. Private _Accept As String = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
  1472. Private _AcceptCharset As String = "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
  1473. Private _AcceptEncoding As String = "gzip, deflate"
  1474. Private _AcceptLanguage As String = "en-us,en;q=0.5"
  1475. Private _AllowExpect100 As Boolean = False
  1476. Private _AllowMetaRedirect As Boolean = True
  1477. Private _AllowWriteStreamBuffering As Boolean = False
  1478. Private _AutoRedirect As Boolean = True
  1479. Private _ContentType As String = "application/x-www-form-urlencoded; charset=UTF-8"
  1480. Private _CustomCookies As HttpCookie() = Nothing
  1481. Private _DebugMode As Boolean = False
  1482. Private _KeepAlive As Boolean = True
  1483. Private _LastRequestUri As String = String.Empty
  1484. Private _LastResponseUri As String = String.Empty
  1485. Private _Proxy As HttpProxy = New HttpProxy
  1486. Private _Referer As String = String.Empty
  1487. Private _SendChunked As Boolean = False
  1488. Private _SendCookies As Boolean = True
  1489. Private _StoreCookies As Boolean = True
  1490. Private _TimeOut As Integer = &HEA60
  1491. Private _UseCustomCookies As Boolean = False
  1492. Private _UserAgent As String = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0"
  1493. Private _Version As Version = HttpVersion.Version11
  1494. Private Const Base36 As String = "0123456789abcdefghijklmnopqrstuvwxyz"
  1495. Public CookieBlacklist As List(Of String) = New List(Of String)
  1496. Public Cookies As CookieContainer = New CookieContainer
  1497. Private disposedValue As Boolean
  1498. Private Shared ReadOnly MIMETypes As Dictionary(Of String, String)
  1499. Public RedirectBlacklist As List(Of String) = New List(Of String)
  1500. Private SessionCookies As List(Of HttpCookie)
  1501. Private ReadOnly Verbs As String() = New String() {"GET", "POST", "PUT"}
  1502.  
  1503. ' Nested Types
  1504. <Serializable()> _
  1505. Public Class HttpCookie
  1506. ' Methods
  1507. Public Sub New()
  1508. Me.Name = String.Empty
  1509. Me.Value = String.Empty
  1510. Me.Domain = String.Empty
  1511. Me.Path = String.Empty
  1512. Me.Expires = New DateTime
  1513. Me.HttpOnly = False
  1514. Me.Secure = False
  1515. Me.Version = -1
  1516. End Sub
  1517.  
  1518. Public Sub New(ByVal cName As String, ByVal cValue As String, ByVal cDomain As String)
  1519. Me.Name = String.Empty
  1520. Me.Value = String.Empty
  1521. Me.Domain = String.Empty
  1522. Me.Path = String.Empty
  1523. Me.Expires = New DateTime
  1524. Me.HttpOnly = False
  1525. Me.Secure = False
  1526. Me.Version = -1
  1527. Me.Name = cName
  1528. Me.Value = cValue
  1529. Me.Domain = cDomain
  1530. End Sub
  1531.  
  1532. Public Sub New(ByVal cName As String, ByVal cValue As String, ByVal cDomain As String, ByVal cPath As String, ByVal cExpires As DateTime, ByVal cHttpOnly As Boolean, ByVal cSecure As Boolean, ByVal cVersion As Integer)
  1533. Me.Name = String.Empty
  1534. Me.Value = String.Empty
  1535. Me.Domain = String.Empty
  1536. Me.Path = String.Empty
  1537. Me.Expires = New DateTime
  1538. Me.HttpOnly = False
  1539. Me.Secure = False
  1540. Me.Version = -1
  1541. Me.Name = cName
  1542. Me.Value = cValue
  1543. Me.Domain = cDomain
  1544. Me.Path = cPath
  1545. Me.Expires = cExpires
  1546. Me.HttpOnly = cHttpOnly
  1547. Me.Secure = cSecure
  1548. Me.Version = cVersion
  1549. End Sub
  1550.  
  1551.  
  1552. ' Fields
  1553. Public Domain As String
  1554. Public Expires As DateTime
  1555. Public HttpOnly As Boolean
  1556. Public Name As String
  1557. Public Path As String
  1558. Public Secure As Boolean
  1559. Public Value As String
  1560. Public Version As Integer
  1561. End Class
  1562.  
  1563. Public Class HttpError
  1564. ' Fields
  1565. Public Exception As Object = Nothing
  1566. Public Html As String = String.Empty
  1567. Public IsProxyError As Boolean = False
  1568. Public Message As String = String.Empty
  1569. End Class
  1570.  
  1571. <StructLayout(LayoutKind.Sequential)> _
  1572. Public Structure HttpProxy
  1573. Public Server As String
  1574. Public Port As Integer
  1575. Public UserName As String
  1576. Public Password As String
  1577. Public Sub New(ByVal pServer As String, ByVal pPort As Integer, Optional ByVal pUserName As String = "", Optional ByVal pPassword As String = "")
  1578. Me = New HttpProxy
  1579. Me.Server = pServer
  1580. Me.Port = pPort
  1581. Me.UserName = pUserName
  1582. Me.Password = pPassword
  1583. End Sub
  1584. End Structure
  1585.  
  1586. Public Class HttpResponse
  1587. ' Fields
  1588. Public Bytes As Byte() = Nothing
  1589. Public [Error] As HttpError = Nothing
  1590. Public Html As String = String.Empty
  1591. Public Image As Image = Nothing
  1592. Public RedirectUrl As String = String.Empty
  1593. Public RequestHeaders As String = String.Empty
  1594. Public RequestUri As String = String.Empty
  1595. Public ResponseHeaders As String = String.Empty
  1596. Public ResponseUri As String = String.Empty
  1597. Public StatusCode As HttpStatusCode
  1598. Public Stream As Stream = Nothing
  1599. Public TimedOut As Boolean = False
  1600. Public WebRequest As HttpWebRequest = Nothing
  1601. Public WebResponse As HttpWebResponse = Nothing
  1602. End Class
  1603.  
  1604. Public Enum MimicBrowser
  1605. ' Fields
  1606. Chrome = 2
  1607. Custom = 3
  1608. Firefox = 0
  1609. InternetExplorer = 1
  1610. End Enum
  1611.  
  1612. <StructLayout(LayoutKind.Sequential)> _
  1613. Public Structure UploadData
  1614. Public ContentType As String
  1615. Public Contents As Byte()
  1616. Public FileName As String
  1617. Public FieldName As String
  1618. Public Sub New(ByVal uContents As Byte(), ByVal uFileName As String, ByVal uFieldName As String)
  1619. Me = New UploadData
  1620. Me.Contents = uContents
  1621. Me.FileName = uFileName
  1622. Me.FieldName = uFieldName
  1623. Me.ContentType = "application/octet-stream"
  1624. End Sub
  1625. End Structure
  1626.  
  1627. Public Enum Verb
  1628. ' Fields
  1629. [GET] = 0
  1630. POST = 1
  1631. PUT = 2
  1632. End Enum
  1633. End Class
Add Comment
Please, Sign In to add comment