webrequest - webresponse again

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
 
C

Cor Ligthert[MVP]

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
 
C

CindyH

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 property> System.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 property> String
+ Keys
{System.Collections.Specialized.NameObjectCollectionBase.KeysCollection}
System.Collections.Specialized.NameObjectCollectionBase.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.
 

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