By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,835 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,835 IT Pros & Developers. It's quick & easy.

xml post slow

P: n/a
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("xmlsi te")), 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.
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
PS: I get the timeout at the line:

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

Steven
steven wrote:
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("xmlsi te")), 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.

Nov 21 '05 #2

P: n/a
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

steven wrote:
PS: I get the timeout at the line:

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

Steven
steven wrote:
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("xmlsi te")), 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.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.