A
Anthony C
This doesn't happen on my development machine (code works perfectly) but on the client's machine, I get an error reported that "too many automatic redirections". I've tried setting the maximum to a large number without prevail.
I used InternetOpenURL in the past (VB6) without incident.
Can anyone help?
Public Function GetPage(ByVal bClearPayload As Boolean) As String
Dim objResponse As WebResponse
Try
Dim objRequest As HttpWebRequest
Dim objRequestStream, objReceiveStream As Stream
Dim objReader As StreamReader
Dim bytPayload() As Byte
Dim szURL As String
'now it's time to encode the payload (payload is set by properties
Dim szPayloadForm As String = GetPayloadFromNameValue(m_objForm)
Dim szPayloadQuery As String = GetPayloadFromNameValue(m_objWebClient.QueryString)
szURL = m_szURL 'module level set by property
If Not szPayloadQuery Is Nothing AndAlso szPayloadQuery.Length > 0 Then
szURL = String.Format("{0}?{1}", szURL, EncodePayload(szPayloadQuery))
End If
objRequest = DirectCast(WebRequest.Create(szURL), HttpWebRequest)
If Not szPayloadForm Is Nothing AndAlso szPayloadForm.Length > 0 Then
objRequest.Method = "POST"
objRequest.ContentType = "application/x-www-form-urlencoded"
bytPayload = System.Text.Encoding.UTF8.GetBytes(EncodePayload(szPayloadForm))
objRequest.ContentLength = bytPayload.Length
objRequestStream = objRequest.GetRequestStream()
objRequestStream.Write(bytPayload, 0, bytPayload.Length)
objRequestStream.Close()
Else
objRequest.Method = "GET"
End If
With objRequest
.CookieContainer = New CookieContainer
End With
objResponse = objRequest.GetResponse() 'EXCEPTION RAISES HERE
objReceiveStream = objResponse.GetResponseStream()
objReader = New StreamReader(objReceiveStream, Encoding.ASCII)
Dim chrRead(256) As Char
Dim nCount As Integer = objReader.Read(chrRead, 0, 256)
Dim sbResponse As New System.Text.StringBuilder
Do Until nCount = 0
Dim str As String = New String(chrRead, 0, nCount)
sbResponse.Append(str)
nCount = objReader.Read(chrRead, 0, 256)
Loop
Return sbResponse.ToString
Catch Ex As Exception
Throw Ex
Finally
If Not objResponse Is Nothing Then
objResponse.Close()
End If
If bClearPayload Then
m_objForm.Clear()
m_objWebClient.QueryString.Clear()
End If
End Try
End Function
I used InternetOpenURL in the past (VB6) without incident.
Can anyone help?
Public Function GetPage(ByVal bClearPayload As Boolean) As String
Dim objResponse As WebResponse
Try
Dim objRequest As HttpWebRequest
Dim objRequestStream, objReceiveStream As Stream
Dim objReader As StreamReader
Dim bytPayload() As Byte
Dim szURL As String
'now it's time to encode the payload (payload is set by properties
Dim szPayloadForm As String = GetPayloadFromNameValue(m_objForm)
Dim szPayloadQuery As String = GetPayloadFromNameValue(m_objWebClient.QueryString)
szURL = m_szURL 'module level set by property
If Not szPayloadQuery Is Nothing AndAlso szPayloadQuery.Length > 0 Then
szURL = String.Format("{0}?{1}", szURL, EncodePayload(szPayloadQuery))
End If
objRequest = DirectCast(WebRequest.Create(szURL), HttpWebRequest)
If Not szPayloadForm Is Nothing AndAlso szPayloadForm.Length > 0 Then
objRequest.Method = "POST"
objRequest.ContentType = "application/x-www-form-urlencoded"
bytPayload = System.Text.Encoding.UTF8.GetBytes(EncodePayload(szPayloadForm))
objRequest.ContentLength = bytPayload.Length
objRequestStream = objRequest.GetRequestStream()
objRequestStream.Write(bytPayload, 0, bytPayload.Length)
objRequestStream.Close()
Else
objRequest.Method = "GET"
End If
With objRequest
.CookieContainer = New CookieContainer
End With
objResponse = objRequest.GetResponse() 'EXCEPTION RAISES HERE
objReceiveStream = objResponse.GetResponseStream()
objReader = New StreamReader(objReceiveStream, Encoding.ASCII)
Dim chrRead(256) As Char
Dim nCount As Integer = objReader.Read(chrRead, 0, 256)
Dim sbResponse As New System.Text.StringBuilder
Do Until nCount = 0
Dim str As String = New String(chrRead, 0, nCount)
sbResponse.Append(str)
nCount = objReader.Read(chrRead, 0, 256)
Loop
Return sbResponse.ToString
Catch Ex As Exception
Throw Ex
Finally
If Not objResponse Is Nothing Then
objResponse.Close()
End If
If bClearPayload Then
m_objForm.Clear()
m_objWebClient.QueryString.Clear()
End If
End Try
End Function