webrequest-webresponse

C

CindyH

Hi

I'm trying to use webrequest - webresponse to post a stream.
I have set up a simple test with one aspx form holding the post code and
trying to get another aspx form to receive the post on localhost.

Can you explain to me the possible reasons why a 'GetResponse' - to send the
data to a server might not be working for a simple text file with one line.

test.text - contains: this is a test.

(Using streamwriter to wrap the text in string and send as stream.
so it looks like this "this is test".)

Either the 'Getresponse' to send to server or the 'reader as streamreader =
new streamreader(page.request.inputstream)' is not working.

From everything I have read and heard this should work.

Thanks, CindyH
 
K

kimiraikkonen

Hi

I'm trying to use webrequest - webresponse to post a stream.
I have set up a simple test with one aspx form holding the post code and
trying to get another aspx form to receive the post on localhost.

Can you explain to me the possible reasons why a 'GetResponse' - to send the
data to a server might not be working for a simple text file with one line..

test.text - contains: this is a test.

(Using streamwriter to wrap the text in string and send as stream.
so it looks like this "this is test".)

Either the 'Getresponse' to send to server or the 'reader as streamreader =
new streamreader(page.request.inputstream)' is not working.

From everything I have read and heard this should work.

Thanks, CindyH

Cindy,
If you just want to upload a file to the server, you can also consider
this using:

Set credentials as you wish (username, password), destination path
should be exact path including protocol prefix(eg: ftp://ftp.server.com/file..xml).

Dim credential As New System.Net.NetworkCredential(<username>,
<password>)
Dim web As New System.Net.WebClient
web.Credentials = credential
web.UploadFile("<destination_path>, <source_filepath>)

There also another functions such as uploadString, uploadData that you
can use.

Hoping it'll be useful,

Onur Güzel
 
M

Martin Honnen

CindyH said:
I'm trying to use webrequest - webresponse to post a stream.
I have set up a simple test with one aspx form holding the post code and
trying to get another aspx form to receive the post on localhost.

Can you explain to me the possible reasons why a 'GetResponse' - to send the
data to a server might not be working for a simple text file with one line.

Make sure you close the request stream before you try to process the
response.
If you still have problems then show us the exact code and exact error
messages you get.
 
C

CindyH

I have to use http xml post as that is what the client wants.



Hi

I'm trying to use webrequest - webresponse to post a stream.
I have set up a simple test with one aspx form holding the post code and
trying to get another aspx form to receive the post on localhost.

Can you explain to me the possible reasons why a 'GetResponse' - to send
the
data to a server might not be working for a simple text file with one
line.

test.text - contains: this is a test.

(Using streamwriter to wrap the text in string and send as stream.
so it looks like this "this is test".)

Either the 'Getresponse' to send to server or the 'reader as streamreader
=
new streamreader(page.request.inputstream)' is not working.

From everything I have read and heard this should work.

Thanks, CindyH

Cindy,
If you just want to upload a file to the server, you can also consider
this using:

Set credentials as you wish (username, password), destination path
should be exact path including protocol prefix(eg:
ftp://ftp.server.com/file.xml).

Dim credential As New System.Net.NetworkCredential(<username>,
<password>)
Dim web As New System.Net.WebClient
web.Credentials = credential
web.UploadFile("<destination_path>, <source_filepath>)

There also another functions such as uploadString, uploadData that you
can use.

Hoping it'll be useful,

Onur Güzel
 
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
 

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