GNG

Connection.vb

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