G
Guest
Hi,
I have an XML file at http://localhost/test.xml that I want to read and then
update.
I can get and read the file no problem with GetResponseStream etc...
The code (see 2 examples below) I am using to write the new xml to that same
location does not give me any error but the file never updates. When I open
the file from XMLSPY with Open URL ... I can read and update it.
Thanks for your help.
First example
Dim myRequest As HttpWebRequest =
CType(WebRequest.Create("http://localhost/test.xml"), HttpWebRequest)
myRequest.Method = "POST"
myRequest.PreAuthenticate = True
Dim networkCredential As New NetworkCredential("myName", "MyPassword",
"MyDomain")
myRequest.Credentials = networkCredential
' this one doesn't work either myRequest.ContentType =
"application/x-www-form-urlencoded"
myRequest.ContentType = "text/xml"
Dim newStream As Stream = myRequest.GetRequestStream()
Dim sw As New StreamWriter(newStream)
sw.Write("<test></test>")
sw.Flush()
sw.Close()
Second example
Dim myRequest As WebRequest =
HttpWebRequest.Create("http://localhost/test.xml")
myRequest.Method = "POST"
myRequest.ContentType = "text/xml"
myRequest.PreAuthenticate = True
Dim networkCredential As New NetworkCredential("myName", "myPassword",
"MyDomain")
myRequest.Credentials = networkCredential
Dim postData As String = "<test></test>"
Dim encoder As New ASCIIEncoding
Dim byteArray As Byte() = encoder.GetBytes(postData)
myRequest.ContentLength = byteArray.Length
Dim readStream As Stream = myRequest.GetRequestStream()
readStream.Write(byteArray, 0, postData.Length)
readStream.Close()
I have an XML file at http://localhost/test.xml that I want to read and then
update.
I can get and read the file no problem with GetResponseStream etc...
The code (see 2 examples below) I am using to write the new xml to that same
location does not give me any error but the file never updates. When I open
the file from XMLSPY with Open URL ... I can read and update it.
Thanks for your help.
First example
Dim myRequest As HttpWebRequest =
CType(WebRequest.Create("http://localhost/test.xml"), HttpWebRequest)
myRequest.Method = "POST"
myRequest.PreAuthenticate = True
Dim networkCredential As New NetworkCredential("myName", "MyPassword",
"MyDomain")
myRequest.Credentials = networkCredential
' this one doesn't work either myRequest.ContentType =
"application/x-www-form-urlencoded"
myRequest.ContentType = "text/xml"
Dim newStream As Stream = myRequest.GetRequestStream()
Dim sw As New StreamWriter(newStream)
sw.Write("<test></test>")
sw.Flush()
sw.Close()
Second example
Dim myRequest As WebRequest =
HttpWebRequest.Create("http://localhost/test.xml")
myRequest.Method = "POST"
myRequest.ContentType = "text/xml"
myRequest.PreAuthenticate = True
Dim networkCredential As New NetworkCredential("myName", "myPassword",
"MyDomain")
myRequest.Credentials = networkCredential
Dim postData As String = "<test></test>"
Dim encoder As New ASCIIEncoding
Dim byteArray As Byte() = encoder.GetBytes(postData)
myRequest.ContentLength = byteArray.Length
Dim readStream As Stream = myRequest.GetRequestStream()
readStream.Write(byteArray, 0, postData.Length)
readStream.Close()