本文整理匯總了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."));
}
}
示例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");
}
}
示例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
}
示例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
}