Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. Function siteRequest(url As String, ByVal Method As String, Optional ByVal data As String = Nothing) As String
  2. Static soucrecode As String = Nothing
  3. Const UserAgent As String = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
  4. Try
  5.  
  6. Dim Request As Net.HttpWebRequest = Net.WebRequest.Create(url)
  7. Request.Accept = "*/*"
  8. Request.Timeout = 10000
  9. Request.Method = Method
  10. Request.UserAgent = UserAgent
  11. Request.AllowAutoRedirect = True
  12. Request.CookieContainer = siteCookies
  13. If Request.Method = "POST" AndAlso data IsNot Nothing Then
  14. Dim postBytes() As Byte = New UTF8Encoding().GetBytes(data)
  15. Request.ContentType = "application/x-www-form-urlencoded"
  16. Request.ContentLength = postBytes.Length
  17. Request.GetRequestStream().Write(postBytes, 0, postBytes.Length)
  18. End If
  19.  
  20. Dim Response As Net.HttpWebResponse = Request.GetResponse()
  21. soucrecode = New IO.StreamReader(Response.GetResponseStream).ReadToEnd()
  22. Response.Close()
  23. Catch e As Exception
  24. MsgBox(e.Message, MsgBoxStyle.Critical)
  25.  
  26. End Try
  27. Return soucrecode
  28. End Function
  29.  
  30. txtLoginSoucre.Text = siteRequest("http://www.SomeSite.com/login.php?do=login", "Post", "username=myUser&password=MyPass") ' Login to site
  31. txtSoucre.Text siteRequest("http: //www.SomeSite.com", "Get") Grab soucrecode
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement