/// <summary> /// /// </summary> /// <param name="url"></param> /// <param name="postData"></param> /// <param name="contentType"></param> /// <returns></returns> public static object PostStream(string url, string postData, string contentType = "application/x-www-form-urlencoded") { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = contentType; request.Method = "POST"; request.Timeout = 300000; byte[] bytes = Encoding.UTF8.GetBytes(postData); request.ContentLength = bytes.Length; Stream writer = request.GetRequestStream(); writer.Write(bytes, 0, bytes.Length); writer.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream() ?? throw new InvalidOperationException(), Encoding.UTF8); //string result = reader.ReadToEnd(); object result = ByteConvertHelper.Stream2Object(reader.BaseStream); response.Close(); return(result); }
public async Task Invoke(HttpContext context) { string path = context.Request.Path; path = path.EndsWith("/") ? path.Substring(0, path.Length - 1) : path; string[] paths = path.Split("/"); if (paths.Length == 3 && paths[2].EndsWith(".rsfs")) { string SvrID = paths[2].Replace(".rsfs", ""); string result = AssxHelper.GetSvrIntfInfo(context, SvrID); context.Response.ContentType = "text/plain; charset=utf-8"; await context.Response.WriteAsync(result); } else if (paths.Length == 3 && paths[2].EndsWith(".proxy")) { string SvrID = paths[2].Replace(".proxy", ""); string result = AssxHelper.GetSvrIntfInfo(context, SvrID); context.Response.ContentType = "text/plain; charset=utf-8"; await context.Response.WriteAsync(result); } else if (paths.Length == 3 && paths[2].EndsWith(".assx")) { string SvrID = paths[2].Replace(".assx", ""); string result = AssxHelper.GetSvrIntfInfo(context, SvrID); context.Response.ContentType = "text/plain; charset=utf-8"; await context.Response.WriteAsync(result); } else if (paths.Length == 4 && paths[2].EndsWith(".proxy")) { string SvrID = paths[2].Replace(".proxy", ""); string method = paths[3]; object result = HttpResultHelper.GetProxyHttpResult(context, SvrID, method); var stream = ByteConvertHelper.Object2Bytes(result); context.Response.ContentType = "application/octet-stream"; context.Response.ContentLength = stream.Length; await context.Response.Body.WriteAsync(stream); } else if (paths.Length == 4 && paths[2].EndsWith(".rsfs")) { string SvrID = paths[2].Replace(".rsfs", ""); string method = paths[3]; Result result = HttpResultHelper.GetRestfulHttpResult(context, SvrID, method); context.Response.ContentType = "text/plain; charset=utf-8"; await context.Response.WriteAsync(JsonConvert.SerializeObject(result)); } else if (paths.Length == 4 && paths[2].EndsWith(".assx")) { string SvrID = paths[2].Replace(".assx", ""); string method = paths[3]; object result = HttpResultHelper.GetHttpResult(context, SvrID, method); context.Response.ContentType = "text/plain; charset=utf-8"; await context.Response.WriteAsync(JsonConvert.SerializeObject(result)); } else if (paths.Length == 3 && paths[2].EndsWith(".sts")) { string SvrID = paths[2].Replace(".sts", ""); string result = TsHelper.GeTsScriptsClient(context, SvrID); context.Response.ContentType = "text/plain; charset=utf-8"; await context.Response.WriteAsync(result); } else { await next.Invoke(context); } }