468,770 Members | 1,917 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,770 developers. It's quick & easy.

webrequest - webresponse again

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


Jun 27 '08 #1
4 1967
Cindy,

what your caller webresponse object (rsp) says about the request?
Jun 27 '08 #2
Cindy,

I don't think so, moreover, because that you wrote
Hi Martin:

You seem to be the only one that knows anything about this.
I don't want to disapoint you in this, like probably more do.

Moreover, as somebody despite this would have helped you, then he/she
probably had done it in your first message thread, repeating asking the same
question means only that the next question which has the slightest sound to
be the same will be ignored by most regulars here, as is a kind of
convention in newsgroups.

Cor
"CindyH" <ch*******@new.rr.comschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
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

Jun 27 '08 #3
Sorry - my mistake - I'm not that familiar with newsgroups and how they
work.

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:69**********************************@microsof t.com...
Cindy,

I don't think so, moreover, because that you wrote
>Hi Martin:

You seem to be the only one that knows anything about this.

I don't want to disapoint you in this, like probably more do.

Moreover, as somebody despite this would have helped you, then he/she
probably had done it in your first message thread, repeating asking the
same question means only that the next question which has the slightest
sound to be the same will be ignored by most regulars here, as is a kind
of convention in newsgroups.

Cor
"CindyH" <ch*******@new.rr.comschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
>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


Jun 27 '08 #4
Hi
In the watch - I'm getting the following for rsp when it comes back from 2nd
form:

rsp {System.Net.HttpWebResponse} System.Net.WebResponse
- [System.Net.HttpWebResponse] {System.Net.HttpWebResponse}
System.Net.HttpWebResponse
CharacterSet "" String
ContentEncoding "" String
ContentLength &H27E Long
ContentType "text/xml; charset=utf-8" String
- Cookies {System.Net.CookieCollection} System.Net.CookieCollection
Count &H0 Integer
IsReadOnly True Boolean
IsSynchronized False Boolean
Item <cannot view indexed propertySystem.Net.Cookie
+ SyncRoot {System.Net.CookieCollection} Object
+ Headers {System.Net.WebHeaderCollection} System.Net.WebHeaderCollection
LastModified #4/30/2008 7:28:48 AM# Date
Method "GET" String
+ ProtocolVersion {System.Version} System.Version
+ ResponseUri {System.Uri} System.Uri
Server "Microsoft-IIS/5.1" String
StatusCode OK System.Net.HttpStatusCode
StatusDescription "OK" String
ContentLength &H27E Long
ContentType "text/xml; charset=utf-8" String
- Headers {System.Net.WebHeaderCollection} System.Net.WebHeaderCollection
+ AllKeys {Length=&H7} String()
Count &H7 Integer
Item <cannot view indexed propertyString
+ Keys
{System.Collections.Specialized.NameObjectCollecti onBase.KeysCollection}
System.Collections.Specialized.NameObjectCollectio nBase.KeysCollection
- ResponseUri {System.Uri} System.Uri
AbsolutePath "/AnnieGreenSprings/(fospog45n5tclv55x22co0r1)/testb.aspx"
String
AbsoluteUri
"http://localhost/AnnieGreenSprings/(fospog45n5tclv55x22co0r1)/testb.aspx"
String
Authority "localhost" String
Fragment "" String
Host "localhost" String
HostNameType Dns System.UriHostNameType
IsDefaultPort True Boolean
IsFile False Boolean
IsLoopback True Boolean
IsUnc False Boolean
LocalPath "/AnnieGreenSprings/(fospog45n5tclv55x22co0r1)/testb.aspx" String
PathAndQuery "/AnnieGreenSprings/(fospog45n5tclv55x22co0r1)/testb.aspx"
String
Port &H50 Integer
Query "" String
Scheme "http" String
SchemeDelimiter "://" String
+ Segments {Length=&H4} String()
UriSchemeFile "file" String
UriSchemeFtp "ftp" String
UriSchemeGopher "gopher" String
UriSchemeHttp "http" String
UriSchemeHttps "https" String
UriSchemeMailto "mailto" String
UriSchemeNews "news" String
UriSchemeNntp "nntp" String
UserEscaped True Boolean
UserInfo "" String
+ rsp {System.Net.HttpWebResponse} System.Net.WebResponse
+ rsp {System.Net.HttpWebResponse} System.Net.WebResponse
System.Net.WebResponse 'WebResponse' is a type and cannot be used as an
expression.
System.Net.WebResponse 'WebResponse' is a type and cannot be used as an
expression.
"Thiago Macedo" <th**********@gmail.comwrote in message
news:9c**********************************@d45g2000 hsc.googlegroups.com...
Cindy,

what your caller webresponse object (rsp) says about the request?

Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by John K. | last post: by
12 posts views Thread by ThyRock | last post: by
reply views Thread by Gordon | last post: by
4 posts views Thread by Savas Ates | last post: by
2 posts views Thread by kkb | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.