huoxudong125 / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

Add Cookie to access vidéo #292

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Add this code 
in  : public class MJPEGStream : IVideoSource

   private bool useCookie = false;     
   string[] NOBSESS;

   public bool UseCookie
        {
            get { return useCookie; }
            set { useCookie = value; }
        }
in : private void WorkerThread( )
     after : request = (HttpWebRequest)WebRequest.Create(source);

     if (useCookie)
     {
        requestCookie = (HttpWebRequest)WebRequest.Create("http://" + request.RequestUri.Authority);
        requestCookie.Timeout = requestTimeout;
        // set login and password
        if ((login != null) && (password != null) && (login != string.Empty))
       requestCookie.Credentials = new NetworkCredential(login, password);
        // force basic authentication through extra headers if required
        if (forceBasicAuthentication)
        {
            string authInfo = string.Format("{0}:{1}", login, password);
            authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
            requestCookie.Headers["Authorization"] = "Basic " + authInfo;
        }
        // get response
        response = requestCookie.GetResponse();
        string[] CookieVal = response.Headers.GetValues("Set-Cookie");
        NOBSESS = CookieVal[0].Split(';');
     }

and before :

// get response
response = request.GetResponse( );:

      //use cookie
      if (useCookie)
      { 
            request.Headers["Cookie"] = NOBSESS[0];
      }

Original issue reported on code.google.com by markko67...@gmail.com on 9 Mar 2012 at 12:10

Attachments: