本文整理汇总了C#中HttpMethod类的典型用法代码示例。如果您正苦于以下问题:C# HttpMethod类的具体用法?C# HttpMethod怎么用?C# HttpMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpMethod类属于命名空间,在下文中一共展示了HttpMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
private static async Task<RequestResponse> ProcessRequest(EasypayConfig config, string data, HttpMethod httpMethod, string path, string reqId)
{
var contentType = httpMethod.Method == "GET" ? "" : "application/vnd.ch.swisscom.easypay.direct.payment+json";
var url = new Uri("https://" + config.Host + config.Basepath + path);
var now = DateTime.Now;
var date = now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss", CultureInfo.GetCultureInfoByIetfLanguageTag("en")) + " +0000"; //Mon, 07 Dec 2015 09:01:30 +0000
var client = new HttpClient();
var request = new HttpRequestMessage(httpMethod, url);
request.Headers.Add("X-SCS-Date", date);
request.Headers.Add("X-Request-Id", reqId);
request.Headers.Add("X-Merchant-Id", config.MerchantId);
request.Headers.Add("X-CE-Client-Specification-Version", "1.1");
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.ch.swisscom.easypay.message.list+json"));
request.Headers.Date = now;
var md5Hash = data != null ? Signature.HashData(Encoding.UTF8.GetBytes(data)) : null;
var hashString = Signature.CreateHashString(httpMethod.Method, md5Hash != null ? Convert.ToBase64String(md5Hash) : "", contentType, date, path);
var signature = Signature.Sign(Encoding.UTF8.GetBytes(config.EasypaySecret), Encoding.UTF8.GetBytes(hashString));
request.Headers.Add("X-SCS-Signature", Convert.ToBase64String(signature));
if (data != null)
{
request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
request.Content = new StringContent(data);
request.Content.Headers.ContentMD5 = md5Hash;
}
var result = await client.SendAsync(request);
var ret = new RequestResponse {Response = await result.Content.ReadAsStringAsync(), StatusCode = result.StatusCode};
return ret;
}
示例2: Request
public string Request(string url, HttpRequestParameter parameter, HttpMethod method, HttpHeader headers)
{
string _params = string.Empty;
if (parameter != null && parameter.Count > 0)
{
_params = parameter.ToString();
}
if (method == HttpMethod.GET)
{
if (url.Contains("?"))
{
url = url + "&" + _params;
}
else
{
url = url + "?" + _params;
}
return HttpGet(url, headers);
}
else
{
return HttpPost(url, _params, headers);
}
}
示例3: CreateTestMessage
internal static HttpRequestMessage CreateTestMessage(string url, HttpMethod httpMethod, HttpConfiguration config)
{
HttpRequestMessage requestMessage = new HttpRequestMessage(httpMethod, url);
IHttpRouteData rd = config.Routes[0].GetRouteData("/", requestMessage);
requestMessage.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, rd);
return requestMessage;
}
示例4: WebRequest
/// <summary>
/// Webs the request.
/// </summary>
/// <param name="method">The method.</param>
/// <param name="url">The URL.</param>
/// <param name="postData">The post data.</param>
/// <returns></returns>
public string WebRequest(HttpMethod method, string url, string postData)
{
this.Message = string.Empty;
HttpWebRequest webRequest = null;
StreamWriter requestWriter = null;
string responseData = "";
webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = method.ToString();
webRequest.ServicePoint.Expect100Continue = false;
if (method == HttpMethod.POST)
{
webRequest.ContentType = "application/x-www-form-urlencoded";
requestWriter = new StreamWriter(webRequest.GetRequestStream());
try
{
requestWriter.Write(postData);
}
catch (Exception ex)
{
this.Message = ex.Message;
}
finally
{
requestWriter.Close();
requestWriter = null;
}
}
responseData = GetWebResponse(webRequest);
webRequest = null;
return responseData;
}
示例5: RequestData
public RequestData(HttpMethod method, string path, PostData<object> data, IConnectionConfigurationValues global, IRequestConfiguration local, IMemoryStreamFactory memoryStreamFactory)
{
this.ConnectionSettings = global;
this.MemoryStreamFactory = memoryStreamFactory;
this.Method = method;
this.PostData = data;
this.Path = this.CreatePathWithQueryStrings(path, this.ConnectionSettings, null);
this.Pipelined = global.HttpPipeliningEnabled || (local?.EnableHttpPipelining).GetValueOrDefault(false);
this.HttpCompression = global.EnableHttpCompression;
this.ContentType = local?.ContentType ?? MimeType;
this.Headers = global.Headers;
this.RequestTimeout = local?.RequestTimeout ?? global.RequestTimeout;
this.PingTimeout =
local?.PingTimeout
?? global?.PingTimeout
?? (global.ConnectionPool.UsingSsl ? ConnectionConfiguration.DefaultPingTimeoutOnSSL : ConnectionConfiguration.DefaultPingTimeout);
this.KeepAliveInterval = (int)(global.KeepAliveInterval?.TotalMilliseconds ?? 2000);
this.KeepAliveTime = (int)(global.KeepAliveTime?.TotalMilliseconds ?? 2000);
this.ProxyAddress = global.ProxyAddress;
this.ProxyUsername = global.ProxyUsername;
this.ProxyPassword = global.ProxyPassword;
this.DisableAutomaticProxyDetection = global.DisableAutomaticProxyDetection;
this.BasicAuthorizationCredentials = local?.BasicAuthenticationCredentials ?? global.BasicAuthenticationCredentials;
this.CancellationToken = local?.CancellationToken ?? CancellationToken.None;
this.AllowedStatusCodes = local?.AllowedStatusCodes ?? Enumerable.Empty<int>();
}
示例6: HasApiRoute
/// <summary>
/// Asserts that the API route exists, has the specified Http method and meets the expectations
/// </summary>
public static void HasApiRoute(HttpConfiguration config, string url, HttpMethod httpMethod, object expectations)
{
var propertyReader = new PropertyReader();
var expectedProps = propertyReader.Properties(expectations);
HasApiRoute(config, url, httpMethod, expectedProps);
}
示例7: MockHttpRequest
public MockHttpRequest(HttpMethod method, string relativeUrl, NameValueCollection queryParams, string requestBody)
{
this.method = method;
this.relativeUrl = relativeUrl;
this.queryParams = queryParams;
this.requestBody = requestBody ?? string.Empty;
}
示例8: Create
public ITwitterQuery Create(string queryURL, HttpMethod httpMethod)
{
var queryURLParameter = new ConstructorNamedParameter("queryURL", queryURL);
var httpMethodParameter = new ConstructorNamedParameter("httpMethod", httpMethod);
return _twitterQueryFactory.Create(queryURLParameter, httpMethodParameter);
}
示例9: WebJob
protected WebJob()
{
Method = HttpMethod.Get;
formData = new List<KeyValuePair<string, string>>();
headers = new List<KeyValuePair<string, string>>();
formString = null;
}
示例10: SendODataHttpRequestWithCanary
public static async Task<byte[]> SendODataHttpRequestWithCanary(Uri uri, HttpMethod method, Stream requestContent, string contentType,
HttpClientHandler clientHandler, SPOAuthUtility authUtility, Dictionary<string, string> headers = null)
{
// Make a post request to {siteUri}/_api/contextinfo to get the canary
var response = await HttpUtility.SendODataJsonRequest(
new Uri(String.Format("{0}/_api/contextinfo", SPOAuthUtility.Current.SiteUrl)),
HttpMethod.Post,
null,
clientHandler,
SPOAuthUtility.Current);
Dictionary<String, IJsonValue> dict = new Dictionary<string, IJsonValue>();
HttpUtility.ParseJson(JsonObject.Parse(Encoding.UTF8.GetString(response, 0, response.Length)), dict);
string canary = dict["FormDigestValue"].GetString();
// Make the OData request passing the canary in the request headers
return await HttpUtility.SendODataHttpRequest(
uri,
method,
requestContent,
contentType,
clientHandler,
SPOAuthUtility.Current,
new Dictionary<string, string> {
{ "X-RequestDigest", canary }
});
}
示例11: Stream
public override Response Stream(Uri url, HttpMethod method, Func<HttpWebResponse, bool, Response> responseBuilderCallback, Stream contents, int bufferSize, long maxReadLength, Dictionary<string, string> headers, Dictionary<string, string> queryStringParameters, RequestSettings settings, Action<long> progressUpdated)
{
if (settings == null)
settings = new JsonRequestSettings();
return base.Stream(url, method, responseBuilderCallback, contents, bufferSize, maxReadLength, headers, queryStringParameters, settings, progressUpdated);
}
示例12: Execute
public override Response Execute(Uri url, HttpMethod method, Func<HttpWebResponse, bool, Response> responseBuilderCallback, string body, Dictionary<string, string> headers, Dictionary<string, string> queryStringParameters, RequestSettings settings)
{
if (settings == null)
settings = new JsonRequestSettings();
return base.Execute(url, method, responseBuilderCallback, body, headers, queryStringParameters, settings);
}
示例13: Request
private Request(string url, HttpMethod httpMethod, string entity = null)
{
_url = url;
_httpMethod = httpMethod;
_entity = entity;
_webRequest = CreateWebRequest(_url, _entity, _httpMethod);
}
示例14: Add
public static BatchStep Add(this IList<BatchStep> list, HttpMethod method, string to, object body)
{
var id = list.Count;
var step = new BatchStep {Method = method, To = to, Body = body, Id = id};
list.Add(step);
return step;
}
示例15: CallAzureMLSM
private async Task<string> CallAzureMLSM(HttpMethod method, string url, string payload)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", this.accessContext.WorkspaceAccessToken);
HttpRequestMessage req = new HttpRequestMessage(method, url);
if (!string.IsNullOrWhiteSpace(payload))
{
req.Content = new StringContent(payload);
req.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
}
HttpResponseMessage response = await client.SendAsync(req);
string result = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return result;
}
else
{
throw new HttpRequestException(string.Format("{0}\n{1}", result, response.StatusCode));
}
}
}