xml post slow

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.
 
S

steven

PS: I get the timeout at the line:

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

Steven
 
S

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
 

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