Advertisement
botdotdot

Sending POST request

Aug 19th, 2011
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.77 KB | None | 0 0
  1.     Private Function POSTRequest(ByVal URL As String, ByVal Data As String) As String
  2.         Dim req As HttpWebRequest = DirectCast(WebRequest.Create(URL), HttpWebRequest)
  3.         req.ContentType = "application/x-www-form-urlencoded"
  4.         req.Method = "POST"
  5.         Dim postData As String = Data
  6.         Dim postBytes As Byte() = Encoding.UTF8.GetBytes(postData)
  7.         req.ContentLength = postBytes.Length
  8.         Dim reqStream As Stream = req.GetRequestStream()
  9.         reqStream.Write(postBytes, 0, postBytes.Length)
  10.         reqStream.Close()
  11.         Dim resp As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
  12.         Dim respText As String = New StreamReader(resp.GetResponseStream(), Encoding.UTF8).ReadToEnd()
  13.         Return respText
  14.     End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement