Which .NET class for HTTP communication?

L

Lamont Sanford

Hi,

I'm designing a client application that communicates with a server via HTTP.
The mechanism is fairly simple:

1) Create an XML-formatted string containing the data to send.
2) Send the data to the server via HTTP using a "POST" method.
3) Wait for the server to return XML-formatted data and then process that
data.

What class should I use to execute the HTTP request? I searched MSDN and
came across HttpWebRequest. It looks pretty straight-forward but I just want
to make sure I'm on the right track before I begin.

A couple of other requirements worth mentioning:

a) I need the request to take place in an asynchronous manner.
b) When the amount of data contained in the POST is large, I'd like to be
able to show the user a progress bar and a message stating something to the
effect of "500,000 of 600,000 bytes sent". Is there anyway to get hold of
that status/progress information while the request is in progress?

Thank YOU.
 
M

Mr. Arnold

Lamont Sanford said:
Hi,

I'm designing a client application that communicates with a server via
HTTP. The mechanism is fairly simple:

1) Create an XML-formatted string containing the data to send.
2) Send the data to the server via HTTP using a "POST" method.
3) Wait for the server to return XML-formatted data and then process that
data.

What class should I use to execute the HTTP request? I searched MSDN and
came across HttpWebRequest. It looks pretty straight-forward but I just
want to make sure I'm on the right track before I begin.

A couple of other requirements worth mentioning:

a) I need the request to take place in an asynchronous manner.
b) When the amount of data contained in the POST is large, I'd like to be
able to show the user a progress bar and a message stating something to
the effect of "500,000 of 600,000 bytes sent". Is there anyway to get hold
of that status/progress information while the request is in progress?
http://www.w3.org/TR/XMLHttpRequest/

The XMLHTTPReqquest works asynchronous. Maybe, you should get the length of
the string, do a Transmission started time, Transmission ended time and
(length) of string sent message.

Here is some stuff on

http://www.developerfusion.co.uk/show/4654/

I am sure if you search Google, you'll find more stuff on the how to(s) and
code examples. This is not a new wheel that you're working with and should
be easy to find examples. The CodeProject is a good place to look for code
examples.
 
H

Henning Krause [MVP - Exchange]

Hello,

from a windows client application, use the HttpWebRequest class.

It has BeginGetRequestStream/EndGetRequestStream,
BeginGetResponse/EndGetResponse methods.

Once you acquired the request stream, you can use the BeginWrite/EndWrite
methods of the stream to send packets of data. Same with the resposne.

This way you can display a progressbar to the user.

Kind regards,
Henning Krause
 
R

Rad [Visual C# MVP]

Hi,

I'm designing a client application that communicates with a server via HTTP.
The mechanism is fairly simple:

1) Create an XML-formatted string containing the data to send.
2) Send the data to the server via HTTP using a "POST" method.
3) Wait for the server to return XML-formatted data and then process that
data.

What class should I use to execute the HTTP request? I searched MSDN and
came across HttpWebRequest. It looks pretty straight-forward but I just want
to make sure I'm on the right track before I begin.

A couple of other requirements worth mentioning:

a) I need the request to take place in an asynchronous manner.
b) When the amount of data contained in the POST is large, I'd like to be
able to show the user a progress bar and a message stating something to the
effect of "500,000 of 600,000 bytes sent". Is there anyway to get hold of
that status/progress information while the request is in progress?

Thank YOU.

I think you might want to take a look at System.Net.WebClient. It does
everything you want perfectly

1) Has an UploadDataAsync method that allows you to upload data
asyncrhonously
2) Has an UploadProgressChanged event that allows you to determine how
much data has been uploaded
 

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