xml post slow

  • Thread starter Thread starter steven
  • Start date Start date
S

steven

I'm posting an XML-string to a website. I'm using the function below.
The problem is that it is extremely slow and I get many time-outs. Does
anyone have any solutions ? Other solutions to post an XML to a website
are also welcome.

Many thanks,

Steven


Private Function postXMLToSite(ByVal xml As String, ByRef errors As
String) As Boolean
Try
Dim bytes As Byte()
bytes = Encoding.UTF8.GetBytes(xml)
Dim request As HttpWebRequest
request =
CType(WebRequest.Create(MySettings.getValue("xmlsite")), HttpWebRequest)
request.Method = "POST"
request.ContentLength = bytes.Length
request.ContentType = "text/xml"
Dim requestStream As Stream
request.GetRequestStream.Write(bytes, 0, bytes.Length)
Dim resp As HttpWebResponse
resp = CType(request.GetResponse, HttpWebResponse)
If resp.StatusCode = HttpStatusCode.OK Then
resp.Close()
Return True
Else
resp.Close()
Return False
End If
Catch ex As Exception
Return False
End Try
End Function




MySettings.getValue("xmlsite") returns the url where the xml is posted to.
 
PS: I get the timeout at the line:

request.GetRequestStream.Write(bytes, 0, bytes.Length)

Steven
 
The stream seems to be the problem. I had this changed and it worked
perfectly:

....
Dim requestStream As Stream
requeststream = request.GetRequestStream
requeststream.Write(bytes, 0, bytes.Length)
requeststream.Close
Dim resp As HttpWebResponse
....

Thanks anyway.

Steven
 
Back
Top