1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Private Function Post_request(ByVal url As String, ByVal data As String) As String
Dim reader As IO.StreamReader = Nothing
Dim writer As IO.StreamWriter = Nothing
Try
Dim hwebrequest As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(url)
hwebrequest.Method = "POST"
hwebrequest.ContentType = "application/x-www-form-urlencoded"
hwebrequest.ContentLength = data.Length
hwebrequest.Timeout = 10000
writer = New IO.StreamWriter(hwebrequest.GetRequestStream, System.Text.Encoding.Default)
writer.Write(data)
writer.Close()
Dim hwebresponse As System.Net.HttpWebResponse = hwebrequest.GetResponse
reader = New IO.StreamReader(hwebresponse.GetResponseStream, System.Text.Encoding.Default)
Dim s As String = reader.ReadToEnd().Trim
reader.Close()
Return s
Catch ex As Exception
If reader IsNot Nothing Then reader.Close()
Log(data, EventLogEntryType.Warning)
Return "ERR:" & ex.Message.ToString
End Try
End Function |
Partager