コード例 #1
0
        private T _SendRequest <T>(
            IRestRequestContext context,
            string url,
            string query,
            HttpRequestOptions opt)
        {
            String queryWithToken = "";

            // Add authentication token to the request.
            if (context.Connection.RequiresTokens)
            {
                var requestUri  = new Uri(url);
                var tokenCookie = new Cookie(
                    TOKEN_COOKIE_NAME,
                    context.Connection.LastToken,
                    TOKEN_COOKIE_PATH,
                    requestUri.Host);

                // Adding a cookie will replace existing one (if any) with the same name, path
                // and domain using case-insensitive comparison.
                opt.CookieContainer.Add(requestUri, tokenCookie);

                // 10.1 routing/VRP services need the "token=..." in the query string
                queryWithToken = AgsHelper.FormatTokenQuery(query, context.Connection.LastToken);
            }
            else
            {
                queryWithToken = query;
            }

            // Add session cookie to the request so all requests in the session would be processed
            // by the same server.
            if (context.SessionCookie != null)
            {
                opt.CookieContainer.Add(context.SessionCookie);
            }

            var    responseInfo = default(HttpResponseInfo);
            string json         = WebHelper.SendRequest(url, queryWithToken, opt, out responseInfo);

            json = _resultPreprocessor(json);

            // Get session cookie from the response. When this cookie is sent in the request
            // we might get no cookie in the response, so we update session cookie only when
            // it's not null.
            var sessionCookie = responseInfo.Cookies[ELB_SESSION_COOKIE_NAME];

            if (sessionCookie != null)
            {
                context.SessionCookie = sessionCookie;
            }

            return(JsonSerializeHelper.DeserializeResponse <T>(json, context.KnownTypes));
        }