Which .NET class for HTTP communication?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lamont Sanford

    #1

    Which .NET class for HTTP communication?

    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.



  • Mr. Arnold

    #2
    Re: Which .NET class for HTTP communication?


    "Lamont Sanford" <yaBigDummy@san ford.sonwrote in message
    news:tdWdndE9MJ RiIoLanZ2dnUVZ_ h2pnZ2d@giganew s.com...
    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?
    >


    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



    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.

    Comment

    • Henning Krause [MVP - Exchange]

      #3
      Re: Which .NET class for HTTP communication?

      Hello,

      from a windows client application, use the HttpWebRequest class.

      It has BeginGetRequest Stream/EndGetRequestSt ream,
      BeginGetRespons e/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


      "Lamont Sanford" <yaBigDummy@san ford.sonwrote in message
      news:tdWdndE9MJ RiIoLanZ2dnUVZ_ h2pnZ2d@giganew s.com...
      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.
      >
      >
      >

      Comment

      • Rad [Visual C# MVP]

        #4
        Re: Which .NET class for HTTP communication?

        On Wed, 24 Oct 2007 16:58:23 -0500, "Lamont Sanford"
        <yaBigDummy@san ford.sonwrote:
        >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.WebC lient. It does
        everything you want perfectly

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

        --

        Comment

        Working...