473,480 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

webrequest-webresponse

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

Jun 27 '08 #1
4 2065
On Apr 29, 6:27 pm, "CindyH" <chensc...@new.rr.comwrote:
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
Jun 27 '08 #2
CindyH wrote:
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.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #3
I have to use http xml post as that is what the client wants.

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:d1**********************************@27g2000h sf.googlegroups.com...
On Apr 29, 6:27 pm, "CindyH" <chensc...@new.rr.comwrote:
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
Jun 27 '08 #4
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

"Martin Honnen" <ma*******@yahoo.dewrote in message
news:ey**************@TK2MSFTNGP05.phx.gbl...
CindyH wrote:
>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.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5319
by: Kevin Steffer | last post by:
Hi group I have a webform which I want to make an ftp connection for a filetransfer from. The thing is when I use the WebRequest class it says "The URI prefix is not recognized" and my URI is...
17
7215
by: James Johnson | last post by:
Dear C#dex, I define a variable: HttpWebRequest webRequest and run the following request webRequest = WebRequest.Create(TARGET_URL) as HttpWebRequest; The webRequest object returns values...
1
3145
by: Tim Regan | last post by:
Hi All, I'm writing an app using WebRequest in csharp. I need the app to respond to the host PC moving from one network to another, e.g. taking a laptop home after work. Currently the...
8
2379
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...
3
1663
by: TR | last post by:
A company that lets affiliates search its database assumes that affiliates will paste code, which looks something like this, into their web pages: <form method="GET" name="search_5"...
0
1207
by: Anonieko | last post by:
..NET 1.0 /1.1 version: ====================== using System.Net; using System.Security.Cryptography.X509Certificates; // ... private void MethodToAccessSSL() {
4
1878
by: Sathyaish | last post by:
The WebRequest class implements IWebRequestCreate and hence, a method Create. This method has two other overloads, one of which is a private method. Here's how it looks: public static...
3
9554
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm trying to create a call to a web page to validate and register software. The code I'm using is: Private Sub OK_Click(ByVal sender As...
0
1164
by: buccsailor | last post by:
Hell there, I tried to post a reply to a message thread created back in July 2006 regarding the override of WebRequest, Closed Conenctions and setting KeepAlive to false,but it's been over 60...
3
8150
by: Dave | last post by:
string m_request = some_web_page; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request ); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Which works...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7059
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6758
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7010
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4499
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3011
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.