jhylands

Post HTTPWebrequest

Jan 3rd, 2012
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.05 KB | None | 0 0
  1. public function PostHTTPWebrequest(byval URL as string, byval PostData as string) as string
  2.         Dim encoding As New System.Text.UTF8Encoding
  3.         Dim byteData As Byte() = encoding.GetBytes(postdata)
  4.         Dim request As System.Net.HttpWebRequest
  5.         request = DirectCast(Net.HttpWebRequest.Create(URL), Net.HttpWebRequest)
  6.         request.Method = "POST"
  7.         request.ContentType = "application/x-www-form-urlencoded"
  8.         request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
  9.         request.ContentLength = byteData.Length
  10.         Dim postreqstream As System.IO.Stream = request.GetRequestStream()
  11.         postreqstream.Write(byteData, 0, byteData.Length)
  12.         postreqstream.Close()
  13.         Dim response As System.Net.HttpWebResponse
  14.         response = DirectCast(request.GetResponse(), Net.HttpWebResponse)
  15.         Dim postreqreader As New System.IO.StreamReader(response.GetResponseStream())
  16.         PostHTTPWebrequest = postreqreader.ReadToEnd
  17. End function
Advertisement
Add Comment
Please, Sign In to add comment