P
Pål Johansen
I made a program that does screen scraping from a website, but when running
this progran on a Win 2003 server the httpwebrequest works fine for a while
but suddenly never returns from the request (and doesn't time out either)
and I have to restart the program. It works fine on a winxp machine.
**********************************************************
Sub Download_WebPage()
Dim strPost As String
Dim Lines As String
Dim DownloadOk As Boolean
Dim LoggedOn As Boolean
If Mode = "Logon" Then
GetLogonAddress()
LoggedOn = False
End If
strPost = Postdata
Dim myWebResponse As HttpWebResponse
Dim myWebRequest As HttpWebRequest
Dim myWriter As StreamWriter
Dim myReader As StreamReader
Dim PageIdOk As Boolean
Try
myWebRequest = CType(WebRequest.Create(Url), HttpWebRequest)
myWebRequest.CookieContainer = MyCookieContainer
If frm.NUpDownTimeout.Enabled Then myWebRequest.Timeout =
frm.NUpDownTimeout.Value * 1000 'Variable timeoutvalue
If strPost.Length > 0 Then 'If no postdata then don't post
myWebRequest.Method = "POST"
myWebRequest.ContentLength = strPost.Length
myWebRequest.ContentType =
"application/x-www-form-urlencoded"
myWriter = New
StreamWriter(myWebRequest.GetRequestStream())
myWriter.Write(strPost)
myWriter.Close()
End If
myWebResponse = CType(myWebRequest.GetResponse(),
HttpWebResponse)
myReader = New
StreamReader(myWebResponse.GetResponseStream())
Pagedata = myReader.ReadToEnd()
myWebResponse.Close()
LoggedOn = True
CheckPageId(PageId, DownloadOk, LoggedOn) 'Checking pageid
and if we are logged on
Catch e As WebException
DownloadOk = False
LoggedOn = False
Pagedata = FilterErrorMsg(e.ToString)
LogError(Now & "----Post_trade_data:" & Chr(13) & Chr(10) &
e.ToString)
Catch OtherExc As Exception
DownloadOk = False
LoggedOn = False
Pagedata = FilterErrorMsg(OtherExc.ToString)
LogError(Now & "----Post_trade_data:" & Chr(13) & Chr(10) &
OtherExc.ToString)
End Try
myWebResponse = Nothing
myWebRequest = Nothing
myWriter = Nothing
myReader = Nothing
RaiseEvent FinishedWeb(Pagedata, ThreadName, DownloadOk,
LoggedOn)
End Sub
this progran on a Win 2003 server the httpwebrequest works fine for a while
but suddenly never returns from the request (and doesn't time out either)
and I have to restart the program. It works fine on a winxp machine.
**********************************************************
Sub Download_WebPage()
Dim strPost As String
Dim Lines As String
Dim DownloadOk As Boolean
Dim LoggedOn As Boolean
If Mode = "Logon" Then
GetLogonAddress()
LoggedOn = False
End If
strPost = Postdata
Dim myWebResponse As HttpWebResponse
Dim myWebRequest As HttpWebRequest
Dim myWriter As StreamWriter
Dim myReader As StreamReader
Dim PageIdOk As Boolean
Try
myWebRequest = CType(WebRequest.Create(Url), HttpWebRequest)
myWebRequest.CookieContainer = MyCookieContainer
If frm.NUpDownTimeout.Enabled Then myWebRequest.Timeout =
frm.NUpDownTimeout.Value * 1000 'Variable timeoutvalue
If strPost.Length > 0 Then 'If no postdata then don't post
myWebRequest.Method = "POST"
myWebRequest.ContentLength = strPost.Length
myWebRequest.ContentType =
"application/x-www-form-urlencoded"
myWriter = New
StreamWriter(myWebRequest.GetRequestStream())
myWriter.Write(strPost)
myWriter.Close()
End If
myWebResponse = CType(myWebRequest.GetResponse(),
HttpWebResponse)
myReader = New
StreamReader(myWebResponse.GetResponseStream())
Pagedata = myReader.ReadToEnd()
myWebResponse.Close()
LoggedOn = True
CheckPageId(PageId, DownloadOk, LoggedOn) 'Checking pageid
and if we are logged on
Catch e As WebException
DownloadOk = False
LoggedOn = False
Pagedata = FilterErrorMsg(e.ToString)
LogError(Now & "----Post_trade_data:" & Chr(13) & Chr(10) &
e.ToString)
Catch OtherExc As Exception
DownloadOk = False
LoggedOn = False
Pagedata = FilterErrorMsg(OtherExc.ToString)
LogError(Now & "----Post_trade_data:" & Chr(13) & Chr(10) &
OtherExc.ToString)
End Try
myWebResponse = Nothing
myWebRequest = Nothing
myWriter = Nothing
myReader = Nothing
RaiseEvent FinishedWeb(Pagedata, ThreadName, DownloadOk,
LoggedOn)
End Sub