當前位置: 首頁>>代碼示例>>C#>>正文


C# HttpRequestMessage.GetType方法代碼示例

本文整理匯總了C#中System.Net.Http.HttpRequestMessage.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpRequestMessage.GetType方法的具體用法?C# HttpRequestMessage.GetType怎麽用?C# HttpRequestMessage.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Net.Http.HttpRequestMessage的用法示例。


在下文中一共展示了HttpRequestMessage.GetType方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CanConvertFromStringReturnsFalseForHttpRequestMessage

 public void CanConvertFromStringReturnsFalseForHttpRequestMessage()
 {
     HttpRequestMessage request = new HttpRequestMessage<int>();
     HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(request.GetType());
     if (converter.CanConvertFromString)
     {
         Assert.Fail(string.Format("CanConvertFromString was wrong for HttpRequestMessage."));
     }
 }
開發者ID:nuxleus,項目名稱:WCFWeb,代碼行數:9,代碼來源:HttpParameterValueConverterTests.cs

示例2: WebApiUsageRequest

 /// <summary>
 /// Initializes a new instance of <see cref="WebApiUsageRequest"/>
 /// </summary>
 /// <param name="request"></param>
 public WebApiUsageRequest(HttpRequestMessage request)
 {
     if (request != null)
     {
         UsageType = request.GetType().Name;
         RequestMethod = request.Method.Method;
         Uri = request.RequestUri.ToString();
         IP = ((HttpContextBase)request.Properties["MS_HttpContext"]).Request.UserHostAddress;
         base.ExtractHeaders(request.Headers);
     }
     else
     {
         throw new ArgumentNullException("Request cannot be null");
     }
 }
開發者ID:Roblinde,項目名稱:GSA-Web-api,代碼行數:19,代碼來源:WebApiUsage.cs

示例3: HttpRequestMessageFactory_AcceptsCustomDelegate

        public void HttpRequestMessageFactory_AcceptsCustomDelegate()
        {
            Configuration configuration = new Configuration(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            );

#if netcore
            configuration.HttpRequestMessageFactory =
                delegate (HttpMethod method, string requestUriString)
                {
                    HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, requestUriString);
                    httpRequestMessage.Headers.Range = new RangeHeaderValue(1024, 2048);
                    return httpRequestMessage;
                };
            Assert.IsNotNull(configuration.HttpRequestMessageFactory);

            var btWebRequest = configuration.HttpRequestMessageFactory(HttpMethod.Get, configuration.Environment.GatewayURL + "/merchants/integration_merchant_id");
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "http://webrequest.com");

            Assert.IsInstanceOf(requestMessage.GetType(), btWebRequest);
            var headerValue = btWebRequest.Headers.Range;
            StringAssert.Contains("1024", btWebRequest.Headers.Range.ToString());
#else
            configuration.HttpWebRequestFactory =
                delegate(String requestUriString)
                {
                    var webRequest = WebRequest.Create(requestUriString) as HttpWebRequest;
                    webRequest.AddRange(1024);
                    return webRequest;
                };

            Assert.IsNotNull(configuration.HttpWebRequestFactory);

            var btWebRequest = configuration.HttpWebRequestFactory(configuration.Environment.GatewayURL + "/merchants/integration_merchant_id");
            HttpWebRequest httpWebRequest = WebRequest.Create("http://webrequest.com") as HttpWebRequest;
            
            Assert.IsInstanceOf(httpWebRequest.GetType(), btWebRequest);
            StringAssert.Contains("1024", btWebRequest.Headers["Range"]);
#endif
        }
開發者ID:braintree,項目名稱:braintree_dotnet,代碼行數:43,代碼來源:ConfigurationTest.cs

示例4: HttpRequestMessageFactory_ReturnsDefaultIfNotSpecified

        public void HttpRequestMessageFactory_ReturnsDefaultIfNotSpecified()
        {
            Configuration configuration = new Configuration(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            );

#if netcore
            Assert.IsNotNull(configuration.HttpRequestMessageFactory);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://webrequest.com");
            Assert.IsInstanceOf(httpRequestMessage.GetType(), configuration.HttpRequestMessageFactory(HttpMethod.Get, configuration.Environment.GatewayURL + "/merchants/integration_merchant_id"));
#else
            Assert.IsNotNull(configuration.HttpWebRequestFactory);
            HttpWebRequest httpWebRequest = WebRequest.Create("http://webrequest.com") as HttpWebRequest;
            Assert.IsInstanceOf(httpWebRequest.GetType(), configuration.HttpWebRequestFactory(configuration.Environment.GatewayURL + "/merchants/integration_merchant_id"));
#endif
        }
開發者ID:braintree,項目名稱:braintree_dotnet,代碼行數:19,代碼來源:ConfigurationTest.cs


注:本文中的System.Net.Http.HttpRequestMessage.GetType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。