コード例 #1
0
        private async void HttpRestServer_ClientRequestEvent(object sender, HttpRestServerService.ClientRequestEventArgs e)
        {
            IO.SimpleHttpServer.Result res = new IO.SimpleHttpServer.Result();

            try
            {
                if (e.RequestMethod == RequestMethodType.GET)
                {
                    //Todo: Type your code here
                    // Example:
                    //if (e.uriString.ToLower() == "/onboardtask/examplegeturi")
                    //{
                    //    string content = JsonConvert.SerializeObject(YourObject);
                    //    res = await RestServer.ServerResponse(HTTPStatusCodes.OK, e.OStream, content);
                    //}
                }
                else if (e.RequestMethod == RequestMethodType.POST)
                {
                    //Todo: Type your code here
                    // Example:
                    //if (e.uriString.ToLower() == "/onboardtask/exampleposturi")
                    //{
                    //    YourObject MyObj = JsonConvert.DeserializeObject<YourObject>(e.HttpContent);
                    //    ....
                    //    string content = JsonConvert.SerializeObject(answer);
                    //    res = await RestServer.ServerResponse(HTTPStatusCodes.OK, e.OStream, content);
                    //}
                }
                else
                {
                    res = await RestServer.ServerResponse(HTTPStatusCodes.Not_Found, e.OStream, null);
                }
            }
            catch (Exception ex)
            {
                await EventLogging.AddLogMessage(MessageType.ExceptionError, this.GetType().Name + " - " + ServiceDisplayName + " - " + "Http REST server exception error! Error: " + ex.Message);
            }
        }
コード例 #2
0
        private async void HttpRestServerForIoTServer_ClientRequestEvent(object sender, ClientRequestEventArgs e)
        {
            IO.SimpleHttpServer.Result res = new IO.SimpleHttpServer.Result();

            try
            {
                if (e.Authorization == AuthorizationType.Basic && e.UserName == HttpServerUserName && e.Password == HttpServerPassword)
                {
                    if (e.RequestMethod == RequestMethodType.GET)
                    {
                        //....
                    }
                    else if (e.RequestMethod == RequestMethodType.POST)
                    {
                        if (e.uriString.ToLower() == "/mes/productreport")
                        {
                            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => MessageList.Items.Add(e.HttpContent));

                            res = await HttpRestServerForIoTServer.ServerResponse(HTTPStatusCodes.OK, e.OStream, null);
                        }
                    }
                    else
                    {
                        res = await HttpRestServerForIoTServer.ServerResponse(HTTPStatusCodes.Not_Found, e.OStream, null);
                    }
                }
                else
                {
                    res = await HttpRestServerForIoTServer.ServerResponse(HTTPStatusCodes.Unauthorized, e.OStream, null);
                }
            }
            catch (Exception ex)
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => MessageList.Items.Add("HttpRestServerForIoTServer error: " + ex.Message));
            }
        }