Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can I avoid waiting for a response after an HttpWebRequest POST?

How can I avoid waiting for a response after an HttpWebRequest POST?

Scheduled Pinned Locked Moved C#
questioncsharpperformance
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kontrolakka
    wrote on last edited by
    #1

    I’m POSTING to an ashx file from my aplication. What I want to do is just post information about some variables of my aplication, and never wait for an answer. What I need is to avoid waiting for an answer, because I don’t need it. I’m accesing the file this way. ----------------------------- string queryString = "http://website/PrivateHandler.ashx"; System.Net.HttpWebRequest myHttpWebRequest = (System.Net.HttpWebRequest)WebRequest.Create(queryString); myHttpWebRequest.Method = "POST"; myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; string strRequest = "mode=1&bID=1&gID=1"; UTF8Encoding objUTF8Encoding = new UTF8Encoding(); byte[] arrRequest = objUTF8Encoding.GetBytes(strRequest); myHttpWebRequest.ContentLength = arrRequest.Length; Stream strmRequest = myHttpWebRequest.GetRequestStream(); strmRequest.Write(arrRequest, 0, arrRequest.Length); strmRequest.Close(); //Wait for an answer (I don’t need an answer). System.Net.WebResponse resp = myHttpWebRequest.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); sr.ReadToEnd(); --------------------------------- WebResponse and ReadToEnd are there because if I don’t read what return, I can only call the ashx file twice and then the system hangs. What I need is to post multiple times and never wait for an answer and waste performance because of that. Is there a way to achieve what I need? Thank you very much. Martín Suárez Viacava

    N X H 3 Replies Last reply
    0
    • K kontrolakka

      I’m POSTING to an ashx file from my aplication. What I want to do is just post information about some variables of my aplication, and never wait for an answer. What I need is to avoid waiting for an answer, because I don’t need it. I’m accesing the file this way. ----------------------------- string queryString = "http://website/PrivateHandler.ashx"; System.Net.HttpWebRequest myHttpWebRequest = (System.Net.HttpWebRequest)WebRequest.Create(queryString); myHttpWebRequest.Method = "POST"; myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; string strRequest = "mode=1&bID=1&gID=1"; UTF8Encoding objUTF8Encoding = new UTF8Encoding(); byte[] arrRequest = objUTF8Encoding.GetBytes(strRequest); myHttpWebRequest.ContentLength = arrRequest.Length; Stream strmRequest = myHttpWebRequest.GetRequestStream(); strmRequest.Write(arrRequest, 0, arrRequest.Length); strmRequest.Close(); //Wait for an answer (I don’t need an answer). System.Net.WebResponse resp = myHttpWebRequest.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); sr.ReadToEnd(); --------------------------------- WebResponse and ReadToEnd are there because if I don’t read what return, I can only call the ashx file twice and then the system hangs. What I need is to post multiple times and never wait for an answer and waste performance because of that. Is there a way to achieve what I need? Thank you very much. Martín Suárez Viacava

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      It appears your are trying to use an HTTPHandler as a Web Service. Why not just create a Web Service?


      only two letters away from being an asset

      K 1 Reply Last reply
      0
      • N Not Active

        It appears your are trying to use an HTTPHandler as a Web Service. Why not just create a Web Service?


        only two letters away from being an asset

        K Offline
        K Offline
        kontrolakka
        wrote on last edited by
        #3

        Thanks for your answer. If I use a WebService, won´t I have a lot of extra overhead? I´m trying to avoid overhead as much as possible. Thanks again. Martín Suárez Viacava

        N 1 Reply Last reply
        0
        • K kontrolakka

          Thanks for your answer. If I use a WebService, won´t I have a lot of extra overhead? I´m trying to avoid overhead as much as possible. Thanks again. Martín Suárez Viacava

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          You will have a better performing solution. A HTTPHandler isn't meant to be used in the manner you are trying. "All an HTTPHandler does really is take an HTTPContext object and work out what to do with it." http://aspalliance.com/articleViewer.aspx?aId=441&pId=[^]


          only two letters away from being an asset

          1 Reply Last reply
          0
          • K kontrolakka

            I’m POSTING to an ashx file from my aplication. What I want to do is just post information about some variables of my aplication, and never wait for an answer. What I need is to avoid waiting for an answer, because I don’t need it. I’m accesing the file this way. ----------------------------- string queryString = "http://website/PrivateHandler.ashx"; System.Net.HttpWebRequest myHttpWebRequest = (System.Net.HttpWebRequest)WebRequest.Create(queryString); myHttpWebRequest.Method = "POST"; myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; string strRequest = "mode=1&bID=1&gID=1"; UTF8Encoding objUTF8Encoding = new UTF8Encoding(); byte[] arrRequest = objUTF8Encoding.GetBytes(strRequest); myHttpWebRequest.ContentLength = arrRequest.Length; Stream strmRequest = myHttpWebRequest.GetRequestStream(); strmRequest.Write(arrRequest, 0, arrRequest.Length); strmRequest.Close(); //Wait for an answer (I don’t need an answer). System.Net.WebResponse resp = myHttpWebRequest.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); sr.ReadToEnd(); --------------------------------- WebResponse and ReadToEnd are there because if I don’t read what return, I can only call the ashx file twice and then the system hangs. What I need is to post multiple times and never wait for an answer and waste performance because of that. Is there a way to achieve what I need? Thank you very much. Martín Suárez Viacava

            X Offline
            X Offline
            xibeifeijian
            wrote on last edited by
            #5

            What about use asynchronous delegate?

            :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

            K 1 Reply Last reply
            0
            • X xibeifeijian

              What about use asynchronous delegate?

              :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

              K Offline
              K Offline
              kontrolakka
              wrote on last edited by
              #6

              Thanks again for your help. xibeifeijian, won't that create a new thread to hear for the async answer? Thanks. Martín

              1 Reply Last reply
              0
              • K kontrolakka

                I’m POSTING to an ashx file from my aplication. What I want to do is just post information about some variables of my aplication, and never wait for an answer. What I need is to avoid waiting for an answer, because I don’t need it. I’m accesing the file this way. ----------------------------- string queryString = "http://website/PrivateHandler.ashx"; System.Net.HttpWebRequest myHttpWebRequest = (System.Net.HttpWebRequest)WebRequest.Create(queryString); myHttpWebRequest.Method = "POST"; myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; string strRequest = "mode=1&bID=1&gID=1"; UTF8Encoding objUTF8Encoding = new UTF8Encoding(); byte[] arrRequest = objUTF8Encoding.GetBytes(strRequest); myHttpWebRequest.ContentLength = arrRequest.Length; Stream strmRequest = myHttpWebRequest.GetRequestStream(); strmRequest.Write(arrRequest, 0, arrRequest.Length); strmRequest.Close(); //Wait for an answer (I don’t need an answer). System.Net.WebResponse resp = myHttpWebRequest.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); sr.ReadToEnd(); --------------------------------- WebResponse and ReadToEnd are there because if I don’t read what return, I can only call the ashx file twice and then the system hangs. What I need is to post multiple times and never wait for an answer and waste performance because of that. Is there a way to achieve what I need? Thank you very much. Martín Suárez Viacava

                H Offline
                H Offline
                Hesham Yassin
                wrote on last edited by
                #7

                put the code in a thread....

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups