I am making a control panel on my forum using vb. I have always wanted to learn httpwebrequest so thought what better place then my own forum.
I can login fine. Download my inbox. Message myself etc not an issue. But if i try to perform another request during the same session nothing happens. I have to close my whole application and reopen it. (no exception just nothing)
Am i missing something here. Do i have to close all streams and clear the cookie container? This is part of an example.
I can login fine. Download my inbox. Message myself etc not an issue. But if i try to perform another request during the same session nothing happens. I have to close my whole application and reopen it. (no exception just nothing)
Am i missing something here. Do i have to close all streams and clear the cookie container? This is part of an example.
VB.NET:
Private Sub SendNewPrivateMessage(ByVal topic As String, ByVal msg As String)
Dim cc As New CookieContainer
Dim postBytes As Byte() = Nothing
Dim requestStream As Stream = Nothing
Dim pageSource As String = String.Empty
Dim response As Net.HttpWebResponse = Nothing
Dim request As Net.HttpWebRequest = CType(Net.WebRequest.Create(SquatJuiceLoginUrl), Net.HttpWebRequest)
Dim loginData As String = String.Format(HttpLoginData, My.Settings.UserAccountName, My.Settings.UserAccountPassword)
Dim msgData As String = String.Format(HttpMsgData, txtNewPostRecipients.Text, topic, msg)
request.ContentType = HttpContentType
request.UserAgent = HttpUserAgent
request.ContentLength = loginData.Length
request.Method = "POST"
request.AllowAutoRedirect = False
request.Timeout = 600 * CInt(txtMessageTimeOut.Text)
request.CookieContainer = cc
requestStream = request.GetRequestStream()
postBytes = System.Text.Encoding.ASCII.GetBytes(loginData)
requestStream.Write(postBytes, 0, postBytes.Length)
response = CType(request.GetResponse(), Net.HttpWebResponse)
pageSource = New StreamReader(response.GetResponseStream()).ReadToEnd()
If Not pageSource.Contains("You have been successfully logged in") Then
rtbRawHttprequestedData.Text = pageSource
MessageBox.Show("Unable to establish a connection. Login fail.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
request = CType(Net.WebRequest.Create(SquatJInbox), Net.HttpWebRequest)
request.ContentType = HttpContentType
request.UserAgent = HttpUserAgent
request.ContentLength = msgData.Length
request.Method = "POST"
request.AllowAutoRedirect = False
request.KeepAlive = True
request.Timeout = 600 * CInt(txtMessageTimeOut.Text)
request.CookieContainer = cc
requestStream = request.GetRequestStream()
postBytes = System.Text.Encoding.ASCII.GetBytes(msgData)
requestStream.Write(postBytes, 0, postBytes.Length)
response = CType(request.GetResponse(), Net.HttpWebResponse)
pageSource = New StreamReader(response.GetResponseStream()).ReadToEnd()
rtbRawHttprequestedData.Text = pageSource
response.GetResponseStream.Close()
request.GetRequestStream.Close()
End Sub