469,607 Members | 1,925 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

n00b question re= WebClient class

I am using the following code to test an .aspx page which has no
presentation and only a handler for the Page_Load event. I am using
this code to POST the contents of an .xml file to the .aspx page.

The page received the file just find and uses Response.Write to send
back a response to indicate it received the file.

I am at a loss to understand how to get this response back from the
WebClient.

I also looked at the HttpRequest class and I can get a response stream
from that, but how do I use that to POST to the .aspx page?

Thanks,

Chris

static void Main(string[] args)
{
WebClient wc = new WebClient();
Stream w =
wc.OpenWrite("http://localhost:2062/TestPage.aspx");
StreamWriter sw = new StreamWriter(w);

using (StreamReader sr = new StreamReader("test.xml"))
{
sw.Write(sr.ReadToEnd());
sw.Flush();
}

sw.Close();

wc.Dispose();
}

Sep 7 '06 #1
1 1140
Chris,
You need to use one of the WebClient methods that returns the response.
UploadString can be used for uploading your Xml, and has a string return
value.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Chris Dunaway" wrote:
I am using the following code to test an .aspx page which has no
presentation and only a handler for the Page_Load event. I am using
this code to POST the contents of an .xml file to the .aspx page.

The page received the file just find and uses Response.Write to send
back a response to indicate it received the file.

I am at a loss to understand how to get this response back from the
WebClient.

I also looked at the HttpRequest class and I can get a response stream
from that, but how do I use that to POST to the .aspx page?

Thanks,

Chris

static void Main(string[] args)
{
WebClient wc = new WebClient();
Stream w =
wc.OpenWrite("http://localhost:2062/TestPage.aspx");
StreamWriter sw = new StreamWriter(w);

using (StreamReader sr = new StreamReader("test.xml"))
{
sw.Write(sr.ReadToEnd());
sw.Flush();
}

sw.Close();

wc.Dispose();
}

Sep 7 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by mc kim via .NET 247 | last post: by
3 posts views Thread by Ram Baruch | last post: by
2 posts views Thread by xzzy | last post: by
1 post views Thread by jmhmaine | last post: by
6 posts views Thread by Giovanni | last post: by
4 posts views Thread by Lehel Kovach | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.