Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Dim sResponse As String = ""
  2. Dim webReq As HttpWebRequest = Nothing
  3. Dim webResp As HttpWebResponse = Nothing
  4. Dim reqStream As Stream = Nothing
  5.  
  6. ' GetPostUrl return the URL only without any parameter.
  7. webReq = DirectCast(WebRequest.Create(ub.GetPostUrl()), HttpWebRequest)
  8.  
  9. ' GetQueryString return the data for the post (param1=value1&param2=value2...)
  10. Dim bytes As Byte() = Encoding.UTF8.GetBytes(ub.GetQueryString())
  11. webReq.Method = "POST"
  12. webReq.ContentType = "application/x-www-form-urlencoded"
  13. webReq.ContentLength = bytes.Length
  14. reqStream = webReq.GetRequestStream()
  15. reqStream.Write(bytes, 0, bytes.Length)
  16. reqStream.Close()
  17.  
  18. Try
  19. webResp = DirectCast(webReq.GetResponse(), HttpWebResponse)
  20.  
  21. If webResp.StatusCode = HttpStatusCode.OK Then
  22. Dim loResponseStream = New StreamReader(webResp.GetResponseStream(), Encoding.UTF8)
  23. sResponse = loResponseStream.ReadToEnd()
  24. End If
  25.  
  26. webResp.Close()
  27. Catch ex As Exception
  28. WriteErrorInFile(ex)
  29. End Try
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement