Guest User

Untitled

a guest
May 24th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #Region "Fonction requête POST"
  2. Private Function RPOST(ByVal url As String, ByVal data As String) As String
  3. ' Create a request using a URL that can receive a post.
  4. Dim request As WebRequest = WebRequest.Create(url)
  5. ' Set the Method property of the request to POST.
  6. request.Method = "POST"
  7. ' Create POST data and convert it to a byte array.
  8. Dim postData As String = data
  9. Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
  10. ' Set the ContentType property of the WebRequest.
  11. request.ContentType = "application/x-www-form-urlencoded"
  12. ' Set the ContentLength property of the WebRequest.
  13. request.ContentLength = byteArray.Length
  14. ' Get the request stream.
  15. Dim dataStream As Stream = request.GetRequestStream()
  16. ' Write the data to the request stream.
  17. dataStream.Write(byteArray, 0, byteArray.Length)
  18. ' Close the Stream object.
  19. dataStream.Close()
  20. ' Get the response.
  21. Dim response As WebResponse = request.GetResponse()
  22. ' Display the status.
  23. 'Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
  24. ' Get the stream containing content returned by the server.
  25. dataStream = response.GetResponseStream()
  26. ' Open the stream using a StreamReader for easy access.
  27. Dim reader As New StreamReader(dataStream)
  28. ' Read the content.
  29. Dim responseFromServer As String = reader.ReadToEnd()
  30. ' Display the content.
  31. MsgBox(DltPrf(responseFromServer))
  32. 'Button2.Enabled = True
  33. 'Button2.Text = "Submit"
  34. Panel1.Visible = False
  35. ' Clean up the streams.
  36. reader.Close()
  37. dataStream.Close()
  38. response.Close()
  39. NoS.Text = ""
  40. DoS.Text = ""
  41. RefreshMYScripts()
  42. RichTextBox1.Text = ""
  43. LoadP.Visible = False
  44. Return True
  45. End Function
  46. #End Region
Add Comment
Please, Sign In to add comment