title: Controlling authentication when using httpwebrequest
body: <p>I've been using HttpWebRequest (currently working as a universal windows app) to get JPEG snapshots from IP security cameras on the home network. I've recently gotten a couple of newer cameras where the authentication seems to go a little haywire. Looking at Wireshark trace, the difference seems to be the following:</p>
  
  <p>The first HTTP GET is sent without credentials which the camera responds with 401 Unauthorized
  The second HTTP GET now has the programmed credentials which the camera then responds with the data</p>
  
  <p>On subsequent requests, the program then seems to send the HTTP GET with the credentials automatically. Unfortunately the camera doesn't seem to like this and responds with 401 Unauthorized (even though the request format is the same as what just worked).</p>
  
  <p>If I exit the program and start again, I see the same initial sequence as above (i.e. HTTP GET without credentials followed by HTTP GET with credentials) and I get a valid response.</p>
  
  <p>Net I can only get one successful request per invocation of the program. My theory is that the camera is therefore relying on seeing a request without credentials to reset something internally (maybe some bug?).</p>
  
  <p>Regardless of what the camera is doing, is there a way of controlling specifically when credentials are sent during HTTP GET?</p>
  
  <p>Code is very simple so far:</p>
  
  <p>HttpWebRequest myHttpWebRequest = WebRequest.CreateHttp(requestURL);
  myHttpWebRequest.Credentials = new NetworkCredential(requestUser, requestPassword);</p>
  
  <p>It executes this every time it wants to get a new snapshot, but even though it is a new HttpWebRequest each time, the credentials seem to be cached and re-presented by default the next time a request is made.</p>