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. webrequest sent twice

webrequest sent twice

Scheduled Pinned Locked Moved C#
help
7 Posts 3 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.
  • F Offline
    F Offline
    Forest4473
    wrote on last edited by
    #1

    Hello I define a HtppWebRequest ending with the following lines : ... req.Credentials = new NetworkCredential(...); Stream theStream = req.GetRequestStream(); theStream.Write(bytes, 0, bytes.Length); theStream.Close(); req.GetResponse(); Then, the request is sent twice. A first time with the theStream.Write line, and a second one with the req.GetResponse() line. I have a 401 (unauthorized) response with the first request and a 403 (forbidden) with the second one. I Wonder if the 403 error is due to the previous 401. In any case, I would not to send the first request. Thanks for your help

    M Richard DeemingR 2 Replies Last reply
    0
    • F Forest4473

      Hello I define a HtppWebRequest ending with the following lines : ... req.Credentials = new NetworkCredential(...); Stream theStream = req.GetRequestStream(); theStream.Write(bytes, 0, bytes.Length); theStream.Close(); req.GetResponse(); Then, the request is sent twice. A first time with the theStream.Write line, and a second one with the req.GetResponse() line. I have a 401 (unauthorized) response with the first request and a 403 (forbidden) with the second one. I Wonder if the 403 error is due to the previous 401. In any case, I would not to send the first request. Thanks for your help

      M Offline
      M Offline
      Michael_Davies
      wrote on last edited by
      #2

      You only need to use the stream if you have parameter data to be written to the URL.

      req.Credentials = new NetworkCredential(...);
      req.GetResponse();

      Will do the trick.

      F 1 Reply Last reply
      0
      • M Michael_Davies

        You only need to use the stream if you have parameter data to be written to the URL.

        req.Credentials = new NetworkCredential(...);
        req.GetResponse();

        Will do the trick.

        F Offline
        F Offline
        Forest4473
        wrote on last edited by
        #3

        No, the GetResponse is not enough because I have data to write into the request. I don't know how to send data without the GetRequestStream.

        M 1 Reply Last reply
        0
        • F Forest4473

          No, the GetResponse is not enough because I have data to write into the request. I don't know how to send data without the GetRequestStream.

          M Offline
          M Offline
          Michael_Davies
          wrote on last edited by
          #4

          Apologise, put my reading glasses on..

          1 Reply Last reply
          0
          • F Forest4473

            Hello I define a HtppWebRequest ending with the following lines : ... req.Credentials = new NetworkCredential(...); Stream theStream = req.GetRequestStream(); theStream.Write(bytes, 0, bytes.Length); theStream.Close(); req.GetResponse(); Then, the request is sent twice. A first time with the theStream.Write line, and a second one with the req.GetResponse() line. I have a 401 (unauthorized) response with the first request and a 403 (forbidden) with the second one. I Wonder if the 403 error is due to the previous 401. In any case, I would not to send the first request. Thanks for your help

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Sounds like a typical authentication challenge - the request doesn't send the credentials unless the server indicates that it needs to. Try setting the PreAuthenticate property[^] to true:

            req.Credentials = new NetworkCredential(...);
            req.PreAuthenticate = true;


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            F 2 Replies Last reply
            0
            • Richard DeemingR Richard Deeming

              Sounds like a typical authentication challenge - the request doesn't send the credentials unless the server indicates that it needs to. Try setting the PreAuthenticate property[^] to true:

              req.Credentials = new NetworkCredential(...);
              req.PreAuthenticate = true;


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              F Offline
              F Offline
              Forest4473
              wrote on last edited by
              #6

              Thanks for your idea, but it doesn't work :-(. I have the same behavior : a 401 error followed by a 403.

              1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                Sounds like a typical authentication challenge - the request doesn't send the credentials unless the server indicates that it needs to. Try setting the PreAuthenticate property[^] to true:

                req.Credentials = new NetworkCredential(...);
                req.PreAuthenticate = true;


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                F Offline
                F Offline
                Forest4473
                wrote on last edited by
                #7

                I've just solved my problem. Le number of - characters was not good on the boundary line.

                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