C
CindyH
Hi - hope someone can help with this - this code was working for a while in
the 'real' code and then suddenly stopped - not sure what happen.
I made two simple forms on localhost to try to test what is going on.
I'm not getting any errors right now, but code is not working either - not
reading the post in second form or else the first form is not sending it
correctly.
---------------------------------------------------------------------------------------------------------------------------------------
This is the Post.xml file I'm sending as stream (string), I have also tried
just simple text file with one line and get same result:
It looks like this when it comes out of the streamreader - before sending to
other form
"<?xml version="1.0"?>
<userlist ACTION="newuser" VENDORNAME="somename">
<amouser AMOAID="101" AMOUSERNAME="Billy Jones" AMOAROLES="Student"
AMOAPRODUCTS="product1,product2" />
</userlist>"
---------------------------------------------------------------------------------------------------------------
This is code - in first form - sends the post to the second form:
This code I've seen on internet in a number of places - all basically the
same.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim fileName As String =
"C:\Inetpub\wwwroot\AnnieGreenSprings\Post.xml"
Dim uri As String = "http://localhost/AnnieGreenSprings/testb.aspx"
Dim req As System.net.WebRequest = Nothing
Dim rsp As System.net.WebResponse = Nothing
Try
req = System.Net.WebRequest.Create(uri)
req.Method = "POST"
req.ContentType = "text/xml"
Dim writer As System.IO.StreamWriter = New
System.IO.StreamWriter(req.GetRequestStream())
writer.WriteLine(GetTextFromXMLFile(fileName))
writer.Close()
rsp = req.GetResponse
Catch webex As System.Net.WebException
Throw webex
Catch Ex As System.Exception
Throw Ex
Finally
If req Is Nothing Then
req.GetRequestStream().Close()
End If
If rsp Is Nothing Then
rsp.GetResponseStream().Close()
End If
End Try
End Sub
Private Function GetTextFromXMLFile(ByVal file As String) As String
Dim reader As New System.IO.StreamReader(file)
Dim ret As String = reader.ReadToEnd()
reader.Close()
Return ret
End Function
------------------------------------------------------------------------------------------------------------------
This is code in the second form that should read the post - instead I'm
getting xmldata = "" - so it looks like it's not receiving post.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim xmldata As String
Response.ContentType = "text/xml"
Response.Clear()
Dim reader As StreamReader = New
StreamReader(Page.Request.InputStream)
xmldata = reader.ReadToEnd
reader.Close()
End Sub
the 'real' code and then suddenly stopped - not sure what happen.
I made two simple forms on localhost to try to test what is going on.
I'm not getting any errors right now, but code is not working either - not
reading the post in second form or else the first form is not sending it
correctly.
---------------------------------------------------------------------------------------------------------------------------------------
This is the Post.xml file I'm sending as stream (string), I have also tried
just simple text file with one line and get same result:
It looks like this when it comes out of the streamreader - before sending to
other form
"<?xml version="1.0"?>
<userlist ACTION="newuser" VENDORNAME="somename">
<amouser AMOAID="101" AMOUSERNAME="Billy Jones" AMOAROLES="Student"
AMOAPRODUCTS="product1,product2" />
</userlist>"
---------------------------------------------------------------------------------------------------------------
This is code - in first form - sends the post to the second form:
This code I've seen on internet in a number of places - all basically the
same.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim fileName As String =
"C:\Inetpub\wwwroot\AnnieGreenSprings\Post.xml"
Dim uri As String = "http://localhost/AnnieGreenSprings/testb.aspx"
Dim req As System.net.WebRequest = Nothing
Dim rsp As System.net.WebResponse = Nothing
Try
req = System.Net.WebRequest.Create(uri)
req.Method = "POST"
req.ContentType = "text/xml"
Dim writer As System.IO.StreamWriter = New
System.IO.StreamWriter(req.GetRequestStream())
writer.WriteLine(GetTextFromXMLFile(fileName))
writer.Close()
rsp = req.GetResponse
Catch webex As System.Net.WebException
Throw webex
Catch Ex As System.Exception
Throw Ex
Finally
If req Is Nothing Then
req.GetRequestStream().Close()
End If
If rsp Is Nothing Then
rsp.GetResponseStream().Close()
End If
End Try
End Sub
Private Function GetTextFromXMLFile(ByVal file As String) As String
Dim reader As New System.IO.StreamReader(file)
Dim ret As String = reader.ReadToEnd()
reader.Close()
Return ret
End Function
------------------------------------------------------------------------------------------------------------------
This is code in the second form that should read the post - instead I'm
getting xmldata = "" - so it looks like it's not receiving post.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim xmldata As String
Response.ContentType = "text/xml"
Response.Clear()
Dim reader As StreamReader = New
StreamReader(Page.Request.InputStream)
xmldata = reader.ReadToEnd
reader.Close()
End Sub