HttpWebRequest and "Too many automatic redirections"

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
 
C

Cor

Hi Anthony,
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 did not look at your code (because it works on your computer why not on the client, than it can not be something by code where my thoughts).

My first thoughts where, has the client maybe some other connection open and is he using http1.1.
As far as I know is it only possible to have two http1.1 connections open in one time.
Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top