예제 #1
0
        protected T DoRequest <T>(OBS.Runtime.Internal.IRequest requestEx, object requestContent)
        {
            ServicePointManager.ServerCertificateValidationCallback +=
                (sender, certificate, chain, sslPolicyErrors) => true;

            ServicePointManager.Expect100Continue = true;
            //如果是4.0以下的版本
            if (int.Parse(Environment.Version.ToString().Split('.').FirstOrDefault()) < 4)
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                                                       | SecurityProtocolType.Ssl3
                                                       | (SecurityProtocolType)768
                                                       | (SecurityProtocolType)3072;
            }
            //如果是4.0以上的版本
            else
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                                                       | SecurityProtocolType.Ssl3
                                                       | (SecurityProtocolType)768
                                                       | (SecurityProtocolType)3072;
            }

            ServicePointManager.DefaultConnectionLimit = 9999;

            HttpMethodName method = (HttpMethodName)Enum.Parse(typeof(HttpMethodName), requestObs.HttpMethod);

            switch (method)
            {
            case HttpMethodName.POST:
            {
                //return _idisRestClient.Post<T>(disConfig.GetFinalBaseURL(), requestEx.ResourcePath, requestEx.Headers, requestContent);
                return(_idisRestClient.Post <T>(requestEx.Endpoint.AbsoluteUri, requestEx.ResourcePath, requestEx.Headers, requestContent));
            }

            case HttpMethodName.GET:
            {
                var requestContext = new RequestContext(true)
                {
                    OriginalRequest = new DISWebServiceRequest(),
                    Request         = requestEx,
                    ClientConfig    = new DISExConfig
                    {
                        Timeout          = new TimeSpan(1, 0, 0, 0),
                        ReadWriteTimeout = new TimeSpan(1, 0, 0, 0)
                    }
                };
                return(_idisRestClient.Get <T>(requestContext, disConfig.GetFinalBaseURL(), requestEx.ResourcePath, requestEx.Headers, requestContent));
            }

            case HttpMethodName.PUT:
                return(_idisRestClient.Put <T>(requestEx.Endpoint.AbsoluteUri, requestEx.ResourcePath, requestEx.Headers, requestContent));

            case HttpMethodName.DELETE:
                return(_idisRestClient.Delete <T>(disConfig.GetFinalBaseURL() + requestEx.ResourcePath, requestEx.Headers, requestContent));
            }

            return(default(T));
        }