コード例 #1
0
 public Dictionary <string, string> ToDictionary()
 {
     return(new Dictionary <string, string>
     {
         { "requestID", ObjectId },
         { "UserID", UserID },
         { "SolverID", SolverID },
         { "RequestType", RequestTypes.ToString() },
         { "CreatedAt", CreatedAt.ToString("yyyy-MM-dd HH:mm:ss") },
         { "NewContent", NewContent },
         { "IsSolved", (Status != UCRProcessStatus.NotSolved).ToString() },
         { "DetailTexts", DetailTexts }
     });
 }
コード例 #2
0
ファイル: WeChat.cs プロジェクト: threezone/DUOJU
        /// <summary>
        /// 调用远程接口
        /// </summary>
        private static T CallRemoteInterface <T>(RequestTypes requestType, RequestContentTypes requestContentType, string url, string parameters = null) where T : class
        {
            var uri     = new Uri(url);
            var request = WebRequest.Create(uri);

            request.Method = requestType.ToString();
            if (requestContentType == RequestContentTypes.FORM)
            {
                request.ContentType = WeChatSettings.REQUEST_CONTENTTYPE_FORM;
            }
            else if (requestContentType == RequestContentTypes.JSON)
            {
                request.ContentType = WeChatSettings.REQUEST_CONTENTTYPE_JSON;
            }
            else if (requestContentType == RequestContentTypes.XML)
            {
                request.ContentType = WeChatSettings.REQUEST_CONTENTTYPE_XML;
            }
            request.Timeout = WeChatSettings.REQUEST_TIMEOUT;

            if (requestType == RequestTypes.POST && !string.IsNullOrEmpty(parameters))
            {
                var bytes = UTF8Encoding.UTF8.GetBytes(parameters);
                request.ContentLength = bytes.Length;
                using (var stream = request.GetRequestStream())
                {
                    stream.Write(bytes, 0, bytes.Length);
                    stream.Close();
                }
            }

            using (var response = request.GetResponse())
                using (var streamReader = new StreamReader(response.GetResponseStream()))
                {
                    var content = streamReader.ReadToEnd();
                    streamReader.Close();

                    if (typeof(T) == typeof(string))
                    {
                        return(content as T);
                    }
                    else
                    {
                        return(JsonHelper.GetModelWithJson <T>(content));
                    }
                }
        }
コード例 #3
0
        //Обрабатывает ответ сервера на ранее поданный запрос-----------------------------------------------------------------------------------------------------------------------------------
        public static void ProcessRequestAnswer(ByteBuffer buffer)
        {
            ushort requestID = buffer.GetUShort();

            ping         = (uint)time.ElapsedMilliseconds - buffer.GetUInt();
            lastPingTime = DateTime.Now;

            Console.WriteLine("ProcessRequestAnswer " + requestID + ". ping: " + ping);

            int requestIndex = requestsList.FindIndex((obj) => obj.requestID == requestID);

            if (requestIndex < 0)
            {
                Client.Log("Ошибка с запросом к серверу № " + requestID, LogTypes.Error);
                RequestTypes requestType = (RequestTypes)buffer.GetByte();
                Client.Log("requestType: " + requestType.ToString() + " size: " + buffer.length, LogTypes.Error);

                return;
            }
            requestsList [requestIndex].requestParseCallback(buffer, requestsList[requestIndex].requestViewCallback);

            requestsList.RemoveAt(requestIndex);
        }
コード例 #4
0
        /// <summary>
        /// For all requests except for auth token generation, the authorization header needs to be added.  Also, we need to let the server know if
        /// we're performing a GET or a POST request
        /// </summary>
        /// <param name="request">The request to which the headers will be assigned</param>
        /// <param name="headerType">The type of request (GET/POST) we'll be making</param>
        private static void AddStandardRequestHeader(HttpsClientRequest request, RequestTypes headerType)
        {
            try
            {
                // Add the authorization header
                request.Header.AddHeader(new HttpsHeader("Authorization",
                                                         "Bearer " + Settings.Token.access_token));

                // Add the GET/POST values based on the type of request that will be sent
                if (headerType == RequestTypes.StandardGetRequest)
                {
                    request.RequestType = RequestType.Get;
                }
                else
                {
                    request.RequestType = RequestType.Post;
                }
            }
            catch (Exception ex)
            {
                CrestronConsole.PrintLine("SimplTeslaMaster.WebRequests.HeaderFactory.AddStandardRequestHeader()::Failed to add request header. Header Type: " + headerType.ToString() +
                                          " " + ex.ToString());
            }
        }
コード例 #5
0
        public const string FORM_BOUNDARY = "----WebKitFormBoundary7MA4YWxkTrZu0gW";        // Sure, this could be a large number of values, but it's nice and easy to copy/paste
                                                                                            // the boundary created by POSTMAN and assign it to a constant

        /// <summary>
        /// Creates the header for an HTTP request
        /// </summary>
        /// <param name="request">The request to which the header will be assigned</param>
        /// <param name="requestType">The type of request being made</param>
        public static void BuildRequestHeaders(HttpsClientRequest request, RequestTypes requestType)
        {
            try
            {
                AddSharedHeaders(request);
            }
            catch (Exception ex)
            {
                CrestronConsole.PrintLine("SimplTeslaMaster.WebRequest.HeaderFactory.BuildRequestHeaders()::Failed to add shared headers. Request type: " + requestType.ToString() +
                                          " " + ex.ToString());
            }

            switch (requestType)
            {
            case RequestTypes.NewToken:
            case RequestTypes.RefreshToken:
                AddFormHeaders(request);
                break;

            default:
                AddStandardRequestHeader(request, requestType);
                break;
            }
        }