Dear all,
I am using the HttpWebRequest and HttpWebRequest to send an XML request
to an ASPX page.
When I use the browser and add my XML request the request is posted
fine and an answer is retrieved.
However, when I use the code below I get an timeout error on the line:
oWebResponse = DirectCast(oWeb Request.GetResp onse, HttpWebResponse )
Does anyone have any ideas why this timeouts in the code, but not the
browser?
Code:
'Issue the Request
Try
oWebRequest =
DirectCast(WebR equest.Create(m _sURIString), HttpWebRequest)
oWebRequest.Met hod = "POST"
oWebRequest.Con tentType = "text/xml"
oWebRequest.Kee pAlive = False 'False cos were only
sending one request
oWebRequest.Con tentLength = sRequest.Length
oWebRequest.Tim eout = iTimeout
oStmWriter = New
StreamWriter(oW ebRequest.GetRe questStream)
oStmWriter.Writ e(sRequest)
oStmWriter.Flus h() 'make sure its done
LogMessage(m_oE ventLog, "Posted request - " +
m_sXMLFile)
Catch WebEx As Net.WebExceptio n
Throw New AppException("G enerated Web Exception:" &
WebEx.Message.T oString, _
ExceptionLevel. Failure, "Sending Request to
URI")
Catch ex As Exception
Throw New AppException(ex .Message,
ExceptionLevel. Failure, "Sending Request to URI")
End Try
'Now read the repsonse
Try
'Read the response coming back from the website
oWebResponse = DirectCast(oWeb Request.GetResp onse,
HttpWebResponse )
oStmReader = New
StreamReader(oW ebResponse.GetR esponseStream)
'Set the Response to a nice string
sResponse = oStmReader.Read ToEnd
LogMessage(m_oE ventLog, "Response recieved - " +
m_sXMLFile)
'Put the XML String into an XML document so that we can
read it nicely
oXMLResponse.Lo adXml(sResponse )
Finally
oStmWriter.Clos e()
If Not IsNothing(oStmR eader) Then
oStmReader.Clos e()
End If
If Not IsNothing(oWebR esponse) Then
oWebResponse.Cl ose()
oWebResponse = Nothing
End If
oStmWriter = Nothing
oStmReader = Nothing
oWebRequest = Nothing
oXML = Nothing
End Try
I am using the HttpWebRequest and HttpWebRequest to send an XML request
to an ASPX page.
When I use the browser and add my XML request the request is posted
fine and an answer is retrieved.
However, when I use the code below I get an timeout error on the line:
oWebResponse = DirectCast(oWeb Request.GetResp onse, HttpWebResponse )
Does anyone have any ideas why this timeouts in the code, but not the
browser?
Code:
'Issue the Request
Try
oWebRequest =
DirectCast(WebR equest.Create(m _sURIString), HttpWebRequest)
oWebRequest.Met hod = "POST"
oWebRequest.Con tentType = "text/xml"
oWebRequest.Kee pAlive = False 'False cos were only
sending one request
oWebRequest.Con tentLength = sRequest.Length
oWebRequest.Tim eout = iTimeout
oStmWriter = New
StreamWriter(oW ebRequest.GetRe questStream)
oStmWriter.Writ e(sRequest)
oStmWriter.Flus h() 'make sure its done
LogMessage(m_oE ventLog, "Posted request - " +
m_sXMLFile)
Catch WebEx As Net.WebExceptio n
Throw New AppException("G enerated Web Exception:" &
WebEx.Message.T oString, _
ExceptionLevel. Failure, "Sending Request to
URI")
Catch ex As Exception
Throw New AppException(ex .Message,
ExceptionLevel. Failure, "Sending Request to URI")
End Try
'Now read the repsonse
Try
'Read the response coming back from the website
oWebResponse = DirectCast(oWeb Request.GetResp onse,
HttpWebResponse )
oStmReader = New
StreamReader(oW ebResponse.GetR esponseStream)
'Set the Response to a nice string
sResponse = oStmReader.Read ToEnd
LogMessage(m_oE ventLog, "Response recieved - " +
m_sXMLFile)
'Put the XML String into an XML document so that we can
read it nicely
oXMLResponse.Lo adXml(sResponse )
Finally
oStmWriter.Clos e()
If Not IsNothing(oStmR eader) Then
oStmReader.Clos e()
End If
If Not IsNothing(oWebR esponse) Then
oWebResponse.Cl ose()
oWebResponse = Nothing
End If
oStmWriter = Nothing
oStmReader = Nothing
oWebRequest = Nothing
oXML = Nothing
End Try
Comment