1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| Dim POSTdata As String = xml
Dim responseData As String = "Aucun résultat."
Dim hwrequest As Net.HttpWebRequest = Net.WebRequest.Create("https://xxxxx.com/xxxx/ws")
Try
hwrequest.AllowWriteStreamBuffering = True
hwrequest.AuthenticationLevel = Net.Security.AuthenticationLevel.None
hwrequest.Accept = "*/*"
hwrequest.AllowAutoRedirect = True
hwrequest.UserAgent = "http_requester/0.1"
hwrequest.Timeout = 60000
hwrequest.Method = "POST"
hwrequest.ContentType = "text/xml; charset=UTF-8" '"application/x-www-form-urlencoded"
Dim utf8Encoding As New System.Text.UTF8Encoding
Dim encodedString() As Byte
encodedString = utf8Encoding.GetBytes(POSTdata)
hwrequest.ContentLength = encodedString.Length
Dim postStream As IO.Stream = hwrequest.GetRequestStream()
postStream.Write(encodedString, 0, encodedString.Length)
postStream.Close()
Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse()
If hwresponse.StatusCode = Net.HttpStatusCode.OK Then
Dim responseStream As IO.StreamReader = New IO.StreamReader(hwresponse.GetResponseStream())
responseData = responseStream.ReadToEnd()
End If
Label1.Text = "> <b><u>Traitement ok. Retour http reçu :</u></b><br><div style='margin-top:10px;color:#336600;font-size:.8em;border:1px solid #777;padding:10px;background-color:#E0E0E0;'>" & responseData & "</div>"
Catch ex As Exception
Label1.Text = "> <b><u>Erreur (traitement impossible) :</u></b><br><div style='margin-top:10px;color:#990000;font-size:.8em;border:1px solid #777;padding:10px;background-color:#E0E0E0;'>" & ex.ToString() & "</div>"
End Try
hwrequest = Nothing |
Partager