473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 2114
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: gizmo | last post by:
Hi, I'm using the following code to request the html source from the quoted site. ...... string url = "http://www1.soccerstand.com/"; WebRequest webRequest = WebRequest.Create(url);...
3
by: Paul | last post by:
Hello, First I want to refer to the problem "WebRequest : execute a button" of a few days ago. The way I solved it, I loose my session, and as a consequence my session variables. I don't want...
8
by: John K. | last post by:
Hi I was wondering if it's possible to use the WebRequest class to access a file on windows shared folder with authentication? If yes, what would the syntax be? I've tried to look this up in the...
0
by: IronYuppie | last post by:
Hi all-- I'm retrieving contents from my site using the retrieving images from the database method listed here: ...
12
by: ThyRock | last post by:
I am working on a WebRequest accessing the US Postal Service WebTools test API. This service uses a DLL file (ShippingAPITest.dll) with a query string which includes XML. The web service accepts...
0
by: Gordon | last post by:
I use the following code to get source HTML. The second line seems to work when I get no response from a site. However, I want to stop the request if it's taking more than 20 - 30 seconds. I can't...
4
by: Savas Ates | last post by:
I have a vb.net web application. I want to post some variables to another web page and take some values back and process them. This is codes in my target url. I should post "langpair" cariable...
2
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an...
1
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.