Пример #1
0
        /// <summary>
        /// Solve Garller API request
        /// </summary>
        /// <param name="ApiRequest">Garller API request</param>
        /// <returns>Garller API response</returns>
        public static API_Response SolveApi(API_Request ApiRequest)
        {
            API_Response ApiResponse = new API_Response();
            switch (ApiRequest.api)
            {
                case "GetTotalCount":
                    ApiResponse.data = GetTotalCount();
                    if (ApiResponse.data != null)
                    {
                        ApiResponse.code = "0";
                    }
                    else
                    {
                        ApiResponse.code = "-1";
                        ApiResponse.data = "获取相片总数目出错";
                    }
                    break;
                case "GetPhotoList":
                    ApiResponse.data = GetPhotoList();
                    if (ApiResponse.data != null)
                    {
                        ApiResponse.code = "0";
                    }
                    else
                    {
                        ApiResponse.code = "-1";
                        ApiResponse.data = "获取相片列表出错";
                    }
                    break;
                default:
                    ApiResponse.code = "-1";
                    ApiResponse.data = "不支持的API调用";
                    break;
            }

            return ApiResponse;
        }
Пример #2
0
 private void SolvePost(HttpRequest Request)
 {
     if (Request.RequestUrl == "/api")
     {
         System.Console.WriteLine("Post Api Request:" + Request.Param["api"]);
         //Get request
         API_Request ApiRequest = new API_Request();
         ApiRequest.api = Request.Param["api"];
         ApiRequest.param = Request.Param["param"];
         //Solve response
         API_Response ApiResponse = Garllery.SolveApi(ApiRequest);
         string pageContent = "{\"code\":\"" + ApiResponse.code + "\",\"data\":\"" +MakeItToStr(ApiResponse.data) + "\"}";
         //Send response
         StringBuilder s = new StringBuilder();
         s.AppendLine("HTTP/1.0 200 OK");
         s.AppendLine("Content_Type:text/html");
         s.AppendLine("Content_Length:" + pageContent.Length);
         s.AppendLine("");
         s.AppendLine(pageContent);
         string DataStr = s.ToString();
         byte[] Data = Encoding.UTF8.GetBytes(DataStr);
         Sock.Send(Data);
     }
     else
     {
         System.Console.WriteLine("Post Request:" + Request.RequestUrl);
     }
 }