httplistener

OAuth 2.0 Authorization for windows desktop application using HttpListener

99封情书 提交于 2021-02-11 18:22:42
问题 I am writing a windows desktop application with External Authentication(Google, Facebook) in C#. I'm using HttpListener to allow a user to get Barer token by External Authentication Service with ASP.NET Web API, but administrator privileges are required for that and I want run without admin mode. My reference was Sample Desktop Application for Windows. Is this the best practice for external authentication provider from C#? Or is there another way to do that? This is my code to get Barer token

C# and running of HttpListener in background

妖精的绣舞 提交于 2021-01-27 12:10:45
问题 I created simple HttpListener that listens to port 9090 and depending on a request's URL writes some info to the console. But I'm stuck :( I thought of multithreading, event based system, but I dind't manage to do anything with it. Here is the code of my listener that I launched as a separate console app: string urlTemplate = String.Format("/prefix/{0}/suffix", id); string prefix = String.Format("http://localhost:9090/"); HttpListener listener = new HttpListener(); listener.Prefixes.Add

HTTPListener “credentials flag” lie

最后都变了- 提交于 2020-02-05 05:19:08
问题 I'm getting the error: "Wildcards cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true." when trying to access a c# httplistener program from a javascript socket.io webpage. what I don't understand is I have the following code setting access control allow credentials to FALSE: // Note: The GetContext method blocks while waiting for a request. HttpListenerContext context = listener.GetContext(); UpdateListbox(PluginCore.listMain, "HTTP Client connected",

HttpListener how to serve images

倾然丶 夕夏残阳落幕 提交于 2020-01-30 06:55:07
问题 I'm making a simple webserver to serve html, css, js & images (done in c#). I am using HttpListener and I can get the html, javascript and css files to work properly. I am just having trouble with the images. This is what I'm using currently: if (request.RawUrl.ToLower().Contains(".png") || request.RawUrl.Contains(".ico") || request.RawUrl.ToLower().Contains(".jpg") || request.RawUrl.ToLower().Contains(".jpeg")) { string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly

Parse POST parameters from HttpListener

自作多情 提交于 2020-01-11 09:24:19
问题 Let's say i have HttpListener. It listen some port and ip. When i send POST request it catch it. How can i parse POST parameters from HttpListenerRequest? HttpListenerContext context = listener.GetContext(); HttpListenerRequest request = context.Request; if ( request.HttpMethod == "POST" ) { // Here i can read all parameters in string but how to parse each one i don't know } 回答1: The POST body (read from the InputStream on the HttpListenerRequest) is parsed using whatever mechanism you choose

.NET HttpListener Prefix issue with anything other than localhost

亡梦爱人 提交于 2020-01-09 10:10:10
问题 I'm trying to use C# and HttpListener with a prefix of anything other than localhost and it fails (i.e. if I give it server1 , i.e. http://localhost:1234 works, but http://server1:1234 fails The code is... HttpListener listener = new HttpListener(); String prefix = @"http://server1:1234"; listener.Prefixes.Add(prefix); listener.Start(); The failure occurs on listener.Start() with an exception of Access is denied. . 回答1: I had the same issue once and i solved it by adding an URL reservation

Why HttpListener Start method Dispose stuff on exception ?

那年仲夏 提交于 2020-01-05 05:30:09
问题 There is something that I really don't understand with the HttpListener. The code below speaks for itself and expose the "issue" in one way. I simply instantiate two different HttpListener with the same single prefix for each one. I then start the first listener, and of course I get an HttpListenerException when I try to start the second one (same prefix) .. so far so good. Ok my fault (or the end user fault if we are going through a configuration tool). No panic, I will just clear the prefix

Simple Web Server: The format of the specified network name is invalid

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-03 09:58:05
问题 I'm having a problem with a simple web server that I am writing. I need to be able to connect to the server through localhost and IP. However, I am having problems connecting through IP. Here is my code: private void start_button_Click(object sender, EventArgs e) { start_button.Text = "Listening..."; HttpListener server = new HttpListener(); server.Prefixes.Add("http://201.0.0.10:69/"); server.Prefixes.Add("http://localhost:69/"); server.Start(); while (true) { HttpListenerContext context =

Simple Web Server: The format of the specified network name is invalid

喜你入骨 提交于 2020-01-03 09:58:01
问题 I'm having a problem with a simple web server that I am writing. I need to be able to connect to the server through localhost and IP. However, I am having problems connecting through IP. Here is my code: private void start_button_Click(object sender, EventArgs e) { start_button.Text = "Listening..."; HttpListener server = new HttpListener(); server.Prefixes.Add("http://201.0.0.10:69/"); server.Prefixes.Add("http://localhost:69/"); server.Start(); while (true) { HttpListenerContext context =

HttpListener Server Header c#

狂风中的少年 提交于 2019-12-30 04:27:25
问题 I am trying to write a C# http server for a personal project, i am wondering how i can change the returned server header from Microsoft-HTTPAPI/2.0, to something else? public class HttpWebServer { private HttpListener Listener; public void Start() { Listener = new HttpListener(); Listener.Prefixes.Add("http://*:5555/"); Listener.Start(); Listener.BeginGetContext(ProcessRequest, Listener); Console.WriteLine("Connection Started"); } public void Stop() { Listener.Stop(); } private void