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 34 35 36 37 38 39 40 41 42 43 44
| Public Function SendRequest(ByVal URL As String, Optional ByVal Message As String = "") As String
Dim HttpWResponse As HttpWebResponse
Dim HttpWRequest As HttpWebRequest
Dim sr As StreamReader
Dim rq As Stream
Dim RawBytes() As Byte
Dim sw As StreamWriter
Dim s as string
Try
HttpWRequest = CType(HttpWebRequest.Create(URL), HttpWebRequest)
HttpWRequest.CookieContainer = CookieJar
If Message <> "" Then
RawBytes = Encoding.ASCII.GetBytes(Message)
HttpWRequest.ContentLength = RawBytes.Length
HttpWRequest.Method = "POST"
HttpWRequest.ContentType = "application/x-www-form-urlencoded"
rq = HttpWRequest.GetRequestStream()
rq.Write(RawBytes, 0, RawBytes.Length)
rq.Flush()
rq.Close()
End If
Try
HttpWResponse = CType(HttpWRequest.GetResponse(), HttpWebResponse)
Catch
End Try
'Read the raw HTML from the request
sr = New StreamReader(HttpWResponse.GetResponseStream(), Encoding.ASCII)
'Convert the stream to a string
s = sr.ReadToEnd()
sr.Close()
HttpWResponse.Close()
Catch e As Exception
Log(e.ToString)
Stop
End Try
Return s
End Function |