473,549 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("h ttp://localhost:2062/TestPage.aspx") ;
StreamWriter sw = new StreamWriter(w) ;

using (StreamReader sr = new StreamReader("t est.xml"))
{
sw.Write(sr.Rea dToEnd());
sw.Flush();
}

sw.Close();

wc.Dispose();
}

Sep 7 '06 #1
1 1310
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("h ttp://localhost:2062/TestPage.aspx") ;
StreamWriter sw = new StreamWriter(w) ;

using (StreamReader sr = new StreamReader("t est.xml"))
{
sw.Write(sr.Rea dToEnd());
sw.Flush();
}

sw.Close();

wc.Dispose();
}

Sep 7 '06 #2

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

Similar topics

0
2027
by: mc kim via .NET 247 | last post by:
What I am trying to is automatic bidding process in Ebay site... WebClient class can uploads form data easily. I have collected ebay url & form data to uploads.. Most of process is quite easy and simple. But ebay webserver send me your password is not valid... But the password is clearly correct.. you can type it at the result page and...
11
942
by: ptass | last post by:
Hi I've installed win2k3 sp1 on a machine where an openRead on any given file was previously working. After installation, I get a webException as follows... ..message "An exception occurred during a webclient request" .._Hresult = "-2146233079" .._COMPlusExceptionCode ="-532459699" Sorry I don't have the whole error, but this seems to...
3
67641
by: Ram Baruch | last post by:
Hi, I'm trying to use WebClient class to upload data. In order to upload it, I need to use my username and password. Does somebody know how can I set it in the WebClient class? Regards, Ram.
2
5353
by: xzzy | last post by:
I have .net 1.1 c# . . . . . using System.Net only lists sockets what do I need to do to be able to do: using System.Net.WebClient;
6
13265
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileID.ToString() + ".pdf");
1
3863
by: jmhmaine | last post by:
I've used the WebClient class on a few projects but I wanted to know if anyone could point to the good resource for Best Practices with this object. The two things I haven't seen in sample code are: 1. How to retrieve connection error messages, such as a DNS resolution error or connection dropped errors. 2. Should I use the Dispose or...
6
22039
by: Giovanni | last post by:
Hi Guys, Really strange problem I am experiencing... I have setup a virtual directory with Read Only permissions on an ISA/IIS server (SBS 2003). In that virt. dir., I placed 1 file (setup.exe). I then use WebClient.DownloadFileAsync (.NET 2.0 Pro.) and all downloads well including progress bar indicator, bytes received, etc... Here is...
4
7754
by: Lehel Kovach | last post by:
I'm having a problem with the WebClient object. When I post data to certain sites, it will receive a command from the webserver (object moved) and continue to the next link by downloading that. The problem is, certain cookies need to be set, and the only way of doing that is not letting the WebClient automatically go on to the next GET in...
2
10143
by: MichaelSchoeler | last post by:
Hi, I'm having problems with the WebClient class regarding UTF-8 encoded data. When I access a specific webservice directly I can see the data arrives in corretly formatted UTF-8. But when I try to pull data from the same webservice url through the WebClient class I get partly garbled UTF-8 data in return. Only some UTF-8 chars (double byte...
0
7471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7985
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7830
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6071
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5387
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5111
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
784
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.