public override string HandleRequest(System.Net.HttpListenerRequest httpRequest) { var body = DeserializeRequestBody <RequestBody>(httpRequest); var assemblies = System.AppDomain.CurrentDomain.GetAssemblies(); var assembly = assemblies.Where(x => x.GetName().Name == "Assembly-CSharp").First(); var method = assembly.GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(Backdoor), false).Length > 0) .Where(m => m.Name == body.selector) .FirstOrDefault(); if (method == null) { throw new CalabashException("Failed to find backdoor method \"" + body.selector + "\""); } var task = CalabashServer.Instance.ExecuteOnMainThread(() => { try { method.Invoke(null, null); } catch { throw new CalabashException("Exception during \"" + body.selector + "\" backdoor method call"); } }); task.Wait(); // For now we do nothing return("{ \"outcome\": \"SUCCESS\", \"results\": [] }"); }
public static string HttpRequestHandler(System.Net.HttpListenerRequest httpRequest) { string queryString = httpRequest.RawUrl; if (queryString == "/favicon.ico") { return(""); } if (queryString.StartsWith("/?")) { queryString = queryString.Substring(2); } // determine display hint from display query value var queries = System.Web.HttpUtility.ParseQueryString(queryString); string displayHint = queries.Get("display"); if (displayHint == null) { displayHint = "home"; } // build the request, load it, execute it, and return HTML Debug.WriteLine("Debug_Clear"); MessageRequest request = new MessageRequest(queryString); Interactor interactor = new AbfBrowser.Interactor(request); Display displayer = interactor.Execute(displayHint); string html = displayer.GetHTML(); return(html); }
public static System.Net.HttpListener StartScriptLogicAsRest(string serviceParameter, Func <object> func) { var listener = new System.Net.HttpListener(); listener.Prefixes.Add(string.Format("http://localhost:4567/{0}/", System.Diagnostics.Process.GetCurrentProcess().ProcessName)); listener.Start(); while (true) { System.Net.HttpListenerContext context = listener.GetContext(); System.Net.HttpListenerRequest request = context.Request; System.Net.HttpListenerResponse response = context.Response; string responseString = func().ToString(); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); // You must close the output stream. output.Close(); } return(listener); }
private Dictionary <string, string> GetGetData(System.Net.HttpListenerRequest request) { var getDataString = request.RawUrl.Substring(request.RawUrl.IndexOf("?") + 1); var getData = parseQueryString(getDataString); return(getData); }
private static void HttpServer_OnDataReceived(System.Net.HttpListenerRequest reqeust, System.Net.HttpListenerResponse response) { if (reqeust.HttpMethod == "POST") { Console.WriteLine("POST"); Stream stream = reqeust.InputStream; BinaryReader binaryReader = new BinaryReader(stream); byte[] data = new byte[reqeust.ContentLength64]; binaryReader.Read(data, 0, (int)reqeust.ContentLength64); String dataString = Encoding.UTF8.GetString(data); Console.WriteLine(dataString); } else { Console.WriteLine("NOT POST"); } string responseString = "<HTML><BODY> Main:" + DateTime.Now + "</BODY></HTML>"; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); // You must close the output stream. output.Close(); }
internal HttpListenerRequestCookieCollection(System.Net.HttpListenerRequest ctx) { this.inner = ctx; foreach (KeyValuePair <string, System.Net.Cookie> cur in this.inner.Cookies) { this.cookies[cur.Key] = cur.Value.ToString(); } }
public override async Task <string> GetResponseString(string method, System.Net.HttpListenerRequest request, System.Collections.Specialized.NameValueCollection queryString, string data) { var devices = await DeviceDatabase.Shared.GetEchoDevices(); var resp = await Task.Run(() => devices.ToDictionary(x => x.Id, x => x.Name).ToJson()); return(resp); }
public override async Task <string> GetResponseString(string method, System.Net.HttpListenerRequest request, NameValueCollection queryString, string data) { var item = await GetResponse(method, request, queryString, data); return(await Task.Run(() => JsonConvert.SerializeObject(item, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }))); }
public string Request(System.Net.HttpListenerRequest Request) { return (KapseleInCatch(new Func <string>(() => { if (null == Request) { return null; } ++RequestAnzaal; ListeRequestLezteZait = Bib3.Glob.StopwatchZaitMiliSictInt(); var Url = Request.RawUrl; FromCustomBotSnapshot VonBotScnapscus = null; try { if (Request.HasEntityBody) { var RequestBodyStream = Request.InputStream; if (null != RequestBodyStream) { var RequestBodyStreamReader = new StreamReader(RequestBodyStream); var RequestBody = RequestBodyStreamReader.ReadToEnd(); VonBotScnapscus = ToCustomBotSnapshot.DeserializeFromString <FromCustomBotSnapshot>(RequestBody); } } } finally { Thread.MemoryBarrier(); this.VonBotScnapscusLezte = VonBotScnapscus; if (null != VonBotScnapscus) { this.RequestedMeasurementTimeLezte = Bib3.Glob.Max(RequestedMeasurementTimeLezte, VonBotScnapscus.MeasurementMemoryRequestTime); } } var NaacBotScnapscus = this.NaacBotScnapscus; Thread.MemoryBarrier(); if (null == NaacBotScnapscus) { return ""; } return ToCustomBotSnapshot.SerializeToString(NaacBotScnapscus); }))); }
public Request(System.Net.HttpListenerRequest Request) : this() { this.Method = Request.HttpMethod; this.URI = Request.Url.AbsolutePath; this.Header = Request.Headers; using (System.IO.StreamReader reader = new System.IO.StreamReader(Request.InputStream)) { this.Body = reader.ReadToEnd(); } }
/// <summary> /// A void function called whenever a response has been received. /// </summary> /// <param name="req">The request object.</param> /// <param name="resp">The response object.</param> /// <param name="log">A logger representing the log.</param> private void TestRESTAPI_ResponseReceived(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse resp, Logger log) { log.Log(LogLevel.INFORMATION, "REST ApiTest: Got request, responding"); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes("{\"success\": \"true\"}")); ms.CopyTo(resp.OutputStream); ms.Close(); resp.Close(); }
public byte[] ProcessRequest(System.Net.HttpListenerRequest request) { if (request.QueryString["exe"] == null) { return(null); } var qq = request.QueryString["exe"]; return(Encoding.ASCII.GetBytes(ExeRunner.Execute(qq, ""))); }
private Dictionary <string, string> GetPostData(System.Net.HttpListenerRequest request) { Dictionary <string, string> postData; using (var reader = new StreamReader(request.InputStream)) { var postedData = reader.ReadToEnd(); postData = parseQueryString(postedData); } return(postData); }
public override async Task <string> GetResponseString(string method, System.Net.HttpListenerRequest request, System.Collections.Specialized.NameValueCollection queryString, string data) { var devices = await DeviceDatabase.Shared.GetEchoDevices(); var resp = await new HueApiResponse { Lights = devices.ToDictionary(x => x.Id, x => new DeviceResponse { Name = x.Name, Uniqueid = x.Id }), }.ToJsonAsync(); return(resp); }
public override async Task <string> GetResponseString(string method, System.Net.HttpListenerRequest request, System.Collections.Specialized.NameValueCollection queryString, string data) { var lightId = queryString ["lightId"]; var device = await DeviceDatabase.Shared.GetDevice(lightId); var resp = await new DeviceResponse { Name = device.Name, Uniqueid = device.Id, }.ToJsonAsync(); return(resp); }
private void WxHttpServer_OnDataReceived(System.Net.HttpListenerRequest reqeust, System.Net.HttpListenerResponse response) { Console.WriteLine(reqeust.Url); string responseString = ""; byte[] buffer = Encoding.UTF8.GetBytes(responseString); response.ContentLength64 = buffer.Length; Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); output.Close(); }
public void HandleGet(System.Net.HttpListenerRequest request, System.Net.HttpListenerResponse response) { try { string path = request.Url.AbsolutePath; if (path.Length < 9) { response.StatusCode = 404; response.WriteResponse("Video not found"); return; } string file = path.Substring(8); if (string.IsNullOrEmpty(file)) { response.StatusCode = 404; response.WriteResponse("Video not found"); return; } var match = Regex.Match(file, "^([a-zA-Z0-9_-])+\\.[a-zA-Z0-9]+$"); if (!match.Success) { response.StatusCode = 404; response.WriteResponse("Video not found"); return; } var jobID = match.Groups[1].Value; string filePath = FFRest.config["workingdir"] + Path.DirectorySeparatorChar + jobID + Path.DirectorySeparatorChar + file; if (!File.Exists(filePath)) { response.StatusCode = 404; response.WriteResponse("Video not found"); return; } response.StatusCode = 200; FileInfo fi = new FileInfo(filePath); response.ContentType = Utility.GetMime(fi.Extension); response.ContentLength64 = fi.Length; using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { Utility.CopyStream(fs, response.OutputStream); } response.OutputStream.Flush(); response.OutputStream.Close(); } catch (Exception ex) { log.Error("Failed to process video request", ex); } }
public byte[] ProcessRequest(System.Net.HttpListenerRequest request) { var filePathOnServer = _webServerRootDir + request.RawUrl.Replace("/", "\\"); if (filePathOnServer.Contains("?")) { filePathOnServer = filePathOnServer.Substring(0, filePathOnServer.IndexOf('?')); } var contentString = File.ReadAllBytes(filePathOnServer); Console.WriteLine(request.Url); return(contentString); }
public HttpListenerRequest(HttpListenerCommunicationContext context, System.Net.HttpListenerRequest request) { _context = context; _nativeRequest = request; Uri = _nativeRequest.Url; CodecParameters = new List<string>(); Headers = new HttpHeaderDictionary(_nativeRequest.Headers); Entity = new HttpEntity(Headers, new HistoryStream(_nativeRequest.InputStream)); if (!string.IsNullOrEmpty(_nativeRequest.ContentType)) Entity.ContentType = new MediaType(_nativeRequest.ContentType); }
public HttpListenerRequest(HttpListenerCommunicationContext context, System.Net.HttpListenerRequest request) { _context = context; _nativeRequest = request; Uri = _nativeRequest.Url; CodecParameters = new List <string>(); Headers = new HttpHeaderDictionary(_nativeRequest.Headers); Entity = new HttpEntity(Headers, _nativeRequest.InputStream); if (!string.IsNullOrEmpty(_nativeRequest.ContentType)) { Entity.ContentType = new MediaType(_nativeRequest.ContentType); } }
private void WebServer_OnWebServerConnectedEvent(System.Net.HttpListenerRequest request, System.Net.HttpListenerResponse response) { __log(txt_webServer_log, "Получено новое сообщение: " + request.RawUrl); string serialResponse = __tryToSendToCOMAndRead(request.RawUrl); if (serialResponse == null) { serialResponse = "Serial порт не прислал ответ!"; } string responseStr = "<html><head><meta charset='utf8'></head><body>" + serialResponse + "</body></html>"; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseStr); response.ContentLength64 = buffer.Length; using (Stream output = response.OutputStream) { output.Write(buffer, 0, buffer.Length); } }
public void ListenerCallback(IAsyncResult result) { try { System.Net.HttpListener listener = (System.Net.HttpListener)result.AsyncState; System.Net.HttpListenerContext context = listener.EndGetContext(result); System.Net.HttpListenerRequest request = context.Request; System.Net.HttpListenerResponse response = context.Response; _iprocessRequest.ProcessRequest(context); } catch (Exception ex) { ServerComms.LogError($"Http Listener falled {ex.Message}"); _listener.BeginGetContext(new AsyncCallback(ListenerCallback), _listener); } }
public void HandleGet(System.Net.HttpListenerRequest request, System.Net.HttpListenerResponse response) { string queryString = request.Url.Query; var queryParts = Server.ParseQueryString(queryString); string type = queryParts.GetFirstValue("type"); if (string.IsNullOrEmpty(type)) { response.WriteResponse(400, "Missing parameter type"); return; } string data = ""; int exitCode; switch (type.ToLower()) { case "formats": data = FFmpeg.Exec("-formats", out exitCode); break; case "codecs": data = FFmpeg.Exec("-codecs", out exitCode); break; case "bsfs": data = FFmpeg.Exec("-bsfs", out exitCode); break; case "protocols": data = FFmpeg.Exec("-protocols", out exitCode); break; case "pix_fmts": data = FFmpeg.Exec("-pix_fmts", out exitCode); break; case "help": data = FFmpeg.Exec("-help", out exitCode); break; } response.WriteResponse(200, data); }
public override async Task <string> GetResponseString(string method, System.Net.HttpListenerRequest request, System.Collections.Specialized.NameValueCollection queryString, string data) { var stateRequest = await data.ToObjectAsync <SetDeviceStateRequest> ().ConfigureAwait(false); var lightId = queryString ["lightId"]; var device = await DeviceDatabase.Shared.GetDevice(lightId); //This will convert the Value property from the Bri from the echo stateRequest.SetValueFromBri(device); Console.WriteLine(data); Console.WriteLine(device); var success = await DeviceManager.Shared.SetDeviceState(device, stateRequest); var result = await new [] { new { success = new Dictionary <string, bool> { { $"lights/{lightId}/state/on", success ? stateRequest.On : !stateRequest.On } } } }.ToJsonAsync(); return(result); // }
public Executer(System.Net.HttpListenerRequest request) { _commands = new ICommand[] { new ClientCloser(), new CompositionAdder(), new CompositionRemover(), new CompositionSearchEngine(), new CompositionsListDisplayer(), //new CompositionsListDisplayerFull(), new PlaylistsListDisplayer(), new PMHelpDisplayer(), }; var reader = new StreamReader(request.InputStream); this.requestCommand = reader.ReadLine() + "\n"; this.requestCommand += reader.ReadLine() + "\n"; this.requestCommand += reader.ReadLine() + "\n"; this.requestCommand += reader.ReadLine(); this._request = reader.ReadToEnd(); }
public override string HandleRequest(System.Net.HttpListenerRequest httpRequest) { /* { * "outcome": "SUCCESS", * "ios_version": "9.3", * "app_id": "com.example.someapp", * "app_name": "Some Application", * "app_base_sdk": "iphonesimulator10.0", * "git": { * "remote_origin": "[email protected]:calabash\\/calabash-ios-server.git", * "branch": "master", * "revision": "3427493" * }, * "iOS_version": "9.3", * "simulator_device": "iPhone", * "version": "0.20.0", * "server_port": 37265, * "model_identifier": "iPhone7,2", * "form_factor": "iphone 6", * "app_version": "3.10.3", * "simulator": "CoreSimulator 303.8 - Device: iPhone 6 - Runtime: iOS 9.3 (13E233) - DeviceType: iPhone 6", * "4inch": false, * "iphone_app_emulated_on_ipad": false, * "device_family": "iPhone", * "screen_dimensions": { * "scale": 2, * "width": 750, * "native_scale": 2, * "sample": 1, * "height": 1334 * }, * "short_version_string": "3.10", * "system": "x86_64", * "device_name": "iPhone Simulator" * } */ return("{ \"outcome\": \"SUCCESS\", \"version\": \"0.20.0\" }"); }
internal HttpListenerRequest(HttpListenerContext context, System.Net.HttpListenerContext innerContext) { this.context = context; this.inner = innerContext.Request; this.Scheme = this.inner.Url.Scheme; this.Host = new HostString(this.inner.UserHostName); this.Method = this.inner.HttpMethod; int qIndex = this.inner.RawUrl.IndexOf('?'); if (qIndex < 0) { this.Path = PathString.FromUriComponent(this.inner.RawUrl); } else { this.Path = PathString.FromUriComponent(this.inner.RawUrl.Substring(0, qIndex)); } this.PathBase = string.Empty; this.Protocol = this.inner.Url.Scheme; this.Query = QueryHelpers.ToQueryCollection(inner.Url); this.QueryString = QueryString.FromUriComponent(inner.Url); }
public void HandleGet(System.Net.HttpListenerRequest request, System.Net.HttpListenerResponse response) { string queryString = request.Url.Query; var queryParts = Server.ParseQueryString(queryString); string jobID = queryParts.GetFirstValue("jobid"); if (string.IsNullOrEmpty(jobID)) { response.WriteResponse(400, "Missing parameter jobID"); return; } TranscodeJob job; if (!jobs.TryGetValue(jobID, out job)) { response.WriteResponse(404, "Job Not Found"); return; } // Build m3u8 file data StringBuilder sb = new StringBuilder(); sb.AppendLine("#EXTM3U"); foreach (var task in job.Results.OrderBy(x => x.BitRate)) { if (task.HasSegments) { sb.AppendLine("#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=" + (task.BitRate)); sb.AppendLine(task.Playlist); } } response.WriteResponse(200, sb.ToString()); }
public void HandlePost(System.Net.HttpListenerRequest request, System.Net.HttpListenerResponse response, Server.RequestData data) { throw new NotImplementedException(); }
public void HandleDelete(System.Net.HttpListenerRequest request, System.Net.HttpListenerResponse response) { throw new NotImplementedException(); }
public override System.Threading.Tasks.Task <List <Device> > GetResponse(string method, System.Net.HttpListenerRequest request, NameValueCollection queryString, string data) { return(DeviceDatabase.Shared.GetAllDevices()); }