public override void HandlePostRequest(HttpProcessor p, StreamReader inputData) { p.WriteSuccess(); }
public void Listen() { try { _listener = new TcpListener(IPAddress.Any, Port); _listener.Start(); while (IsActive) { TcpClient s = _listener.AcceptTcpClient(); HttpProcessor processor = new HttpProcessor(s, this); Thread thread = new Thread(processor.Process); thread.Start(); Thread.Sleep(1); } } catch (SocketException e) { if (e.ErrorCode != 10004) //Ignore 10004, which is thrown when the thread gets terminated throw; } }
public override void HandleGetRequest(HttpProcessor p) { p.WriteSuccess(); if (p.HttpUrl == "/favicon.ico") return; Thread t; if (_type == AuthType.Authorization) { String url = p.HttpUrl; url = url.Substring(2, url.Length - 2); NameValueCollection col = HttpUtility.ParseQueryString(url); if (col.Keys.Get(0) != "code") { p.OutputStream.WriteLine("<html><body><h1>Spotify Auth canceled!</h1></body></html>"); t = new Thread(o => { //_funcOne(null, col.Get(1), col.Get(0)); if(OnAuth != null) OnAuth(new AuthEventArgs() { State = col.Get(1), Error = col.Get(0), }); }); } else { p.OutputStream.WriteLine("<html><body><h1>Spotify Auth successful!</h1><script>window.close();</script></body></html>"); t = new Thread(o => { if(OnAuth != null) OnAuth(new AuthEventArgs() { Code = col.Get(0), State = col.Get(1) }); }); } } else { if (p.HttpUrl == "/") { p.OutputStream.WriteLine("<html><body>" + "<script>" + "" + "var hashes = window.location.hash;" + "hashes = hashes.replace('#','&');" + "window.location = hashes" + "</script>" + "<h1>Spotify Auth successful!<br>Please copy the URL and paste it into the application</h1></body></html>"); return; } String url = p.HttpUrl; url = url.Substring(2, url.Length - 2); NameValueCollection col = HttpUtility.ParseQueryString(url); if (col.Keys.Get(0) != "access_token") { p.OutputStream.WriteLine("<html><body><h1>Spotify Auth canceled!</h1></body></html>"); t = new Thread(o => { if (OnAuth != null) OnAuth(new AuthEventArgs() { Error = col.Get(0), State = col.Get(1) }); }); } else { p.OutputStream.WriteLine("<html><body><h1>Spotify Auth successful!</h1><script>window.close();</script></body></html>"); t = new Thread(o => { if (OnAuth != null) OnAuth(new AuthEventArgs() { Code = col.Get(0), TokenType = col.Get(1), ExpiresIn = Convert.ToInt32(col.Get(2)), State = col.Get(3) }); }); } } t.Start(); }
public abstract void HandleGetRequest(HttpProcessor p);
public abstract void HandlePostRequest(HttpProcessor p, StreamReader inputData);
public override void HandleGetRequest(HttpProcessor p) { p.WriteSuccess(); if (p.HttpUrl == "/favicon.ico") { return; } Thread t; if (_type == AuthType.Authorization) { string url = p.HttpUrl; url = url.Substring(2, url.Length - 2); NameValueCollection col = HttpUtility.ParseQueryString(url); if (col.Keys.Get(0) != "code") { p.OutputStream.WriteLine("<html><body><h1>Spotify Auth canceled!</h1></body></html>"); t = new Thread(o => { OnAuth?.Invoke(new AuthEventArgs() { State = col.Get(1), Error = col.Get(0), }); }); } else { p.OutputStream.WriteLine("<html><body><h1>Spotify Auth successful!</h1><script>window.close();</script></body></html>"); t = new Thread(o => { OnAuth?.Invoke(new AuthEventArgs() { Code = col.Get(0), State = col.Get(1) }); }); } } else { if (p.HttpUrl == "/") { p.OutputStream.WriteLine("<html><body>" + "<script>" + "" + "var hashes = window.location.hash;" + "hashes = hashes.replace('#','&');" + "window.location = hashes" + "</script>" + "<h1>Spotify Auth successful!<br>Please copy the URL and paste it into the application</h1></body></html>"); return; } string url = p.HttpUrl; url = url.Substring(2, url.Length - 2); NameValueCollection col = HttpUtility.ParseQueryString(url); if (col.Keys.Get(0) != "access_token") { p.OutputStream.WriteLine("<html><body><h1>Spotify Auth canceled!</h1></body></html>"); t = new Thread(o => { OnAuth?.Invoke(new AuthEventArgs() { Error = col.Get(0), State = col.Get(1) }); }); } else { p.OutputStream.WriteLine("<html><body><h1>Spotify Auth successful!</h1><script>window.close();</script></body></html>"); t = new Thread(o => { OnAuth?.Invoke(new AuthEventArgs() { Code = col.Get(0), TokenType = col.Get(1), ExpiresIn = Convert.ToInt32(col.Get(2)), State = col.Get(3) }); }); } } t.Start(); }
public void Listen() { try { _listener = new TcpListener(IPAddress.Any, Port); _listener.Start(); while (IsActive) { TcpClient s = _listener.AcceptTcpClient(); HttpProcessor processor = new HttpProcessor(s, this); Thread thread = new Thread(processor.Process); thread.Start(); Thread.Sleep(1); } } catch (Exception) { // ignored } }