public HTTPServer(int port) : base(port) { CallFuncThriftEx <T> handler = new CallFuncThriftEx <T>(); CallFuncThrift.Processor processor = new CallFuncThrift.Processor(handler); string serviceUrl = "http://localhost:99/"; TProtocolFactory protocolFactory = new TJSONProtocol.Factory(); THttpHandler httpServer = new THttpHandler(processor, protocolFactory); HttpListener httpListener = new HttpListener(); httpListener.Prefixes.Add(serviceUrl); httpListener.Start(); //Logger.log("创建ThriftServer", $"端口号:{port}"); }
private static void Main(string[] args) { var handler = new OpenGraphHandler(); var processor = new OpenGraphService.Processor(handler); var httpHanlder = new THttpHandler(processor, new TJSONProtocol.Factory()); var listener = new HttpListener(); listener.Prefixes.Add("http://localhost:8080/"); Console.WriteLine("Starting the server..."); listener.Start(); while (true) { if (listener.IsListening) { var context = listener.GetContext(); context.Response.AddHeader("Access-Control-Allow-Origin", "*"); context.Response.AddHeader("Access-Control-Allow-Methods", "POST,GET,PUT,DELETE"); context.Response.AddHeader("Access-Control-Allow-Headers", "Accept, Content-type"); if (context.Request.HttpMethod == "OPTIONS") { context.Response.OutputStream.Close(); } else { httpHanlder.ProcessRequest(context); } } else { Thread.Sleep(1000); } } }