本文整理汇总了C#中System.Net.HttpVerb类的典型用法代码示例。如果您正苦于以下问题:C# HttpVerb类的具体用法?C# HttpVerb怎么用?C# HttpVerb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpVerb类属于System.Net命名空间,在下文中一共展示了HttpVerb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPageAsync
public async Task<string> GetPageAsync(string url, HttpVerb verb, string referrer = null)
{
var responseText = "";
using (var request = RequestBuilder.Build(url, CommonHeaders(referrer), CookieJar))
{
request.Method = verb.ToVerbString();
using (var response = await request.GetResponseAsync().ConfigureAwait(false))
{
using (var stream = await response.GetResponseStreamAsync())
{
using (var sr = new StreamReader(stream))
{
responseText = sr.ReadToEnd();
}
}
var doc = new HtmlDocument();
doc.LoadHtml(responseText);
var scripts = doc.DocumentNode.Descendants("script");
foreach (var s in scripts.Where(s => s.InnerText.Contains("top.location")))
{
var newUrl = s.InnerText.Split('=')[1].Trim().Trim(new[] {' ', ';', '"'});
return await GetPageAsync(newUrl, verb).ConfigureAwait(false);
}
}
}
return responseText;
}
示例2: RestClient
public RestClient(string endpoint, HttpVerb method)
{
EndPoint = endpoint;
Method = method;
ContentType = "application/json";//"text/xml";
PostData = "";
}
示例3: RestClient
/**
* RestClient with an end point, request type, post-data if any and content type
*/
public RestClient (string endpoint, HttpVerb method, string postData,string contentTypeIdentifier)
{
EndPoint = endpoint;
Method = method;
ContentType = contentTypeIdentifier;
PostData = postData;
}
示例4: RestClient
public RestClient(string endpoint, HttpVerb method, string postData)
: this()
{
EndPoint = endpoint;
Method = method;
PostData = postData;
}
示例5: SimpleRestClient
public SimpleRestClient(string endpoint, HttpVerb method)
{
EndPoint = endpoint;
Method = method;
ContentType = "text/json";
PostData = string.Empty;
}
示例6: RestHelper
public RestHelper(string endpoint, HttpVerb method)
{
EndPoint = endpoint;
Method = method;
ContentType = "application/json";
PostData = "";
}
示例7: MakeRequest
/// <summary>
/// Make an HTTP request, with the given query args
/// </summary>
/// <param name="url">The URL of the request</param>
/// <param name="httpVerb">The HTTP verb to use</param>
/// <param name="argument">String thar represents the request data, must be in JSON format</param>
private static string MakeRequest(Uri url, HttpVerb httpVerb, string argument = null)
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = httpVerb.ToString();
request.ContentType = "application/json";
if (httpVerb == HttpVerb.POST)
{
var encoding = new ASCIIEncoding();
var postDataBytes = new byte[0];
if (argument != null)
{
postDataBytes = encoding.GetBytes(argument);
}
request.ContentLength = postDataBytes.Length;
var requestStream = request.GetRequestStream();
requestStream.Write(postDataBytes, 0, postDataBytes.Length);
requestStream.Close();
}
try
{
using (var response = (HttpWebResponse)request.GetResponse())
{
var reader = new StreamReader(response.GetResponseStream());
return reader.ReadToEnd();
}
}
catch (WebException e)
{
throw new CoticulaApiException("Server Error", e.Message);
}
}
示例8: RestClient
public RestClient(string endpoint, HttpVerb method, Object postObj)
{
this.EndPoint = endpoint;
this.Method = method;
this.ContentType = "application/json;charset=UTF-8";
this.PostData = Newtonsoft.Json.JsonConvert.SerializeObject(postObj);
}
示例9: Build
/// <summary>
/// Builds a HTTP request from the given arguments.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="verb">The verb.</param>
/// <param name="agent">The agent.</param>
/// <param name="cookies">The cookies.</param>
/// <param name="referer">The referer.</param>
/// <param name="retries">The retries.</param>
/// <param name="timeout">The timeout.</param>
/// <param name="accept">The accept.</param>
/// <param name="encoding">The encoding.</param>
/// <returns></returns>
public HttpRequest Build(string url, HttpVerb verb , string agent, CookieContainer cookies = null, string referer = "", int retries = 0, int timeout = 10000, BaseMime accept = null, Encoding encoding = null)
{
var request = new HttpRequest
{
Url = url,
UserAgent = agent,
Verb = verb,
Referer = referer,
Retries = retries,
Timeout = timeout,
Encoding = encoding ?? Encoding.UTF8
};
if (accept != null)
{
request.Accept = accept.ToString();
}
if (cookies != null)
{
request.Cookies = cookies;
}
return request;
}
示例10: HttpClient
public HttpClient(string endpoint, HttpVerb httpVerb, NameValueCollection headers, string contentType, string parameters)
{
try
{
this.Request = (HttpWebRequest)WebRequest.Create(endpoint);
this.Request.ContentLength = 0;
this.Request.ContentType = contentType.ToString();
this.Request.Method = httpVerb.ToString();
if (headers != null)
{
foreach (var key in headers.AllKeys)
{
this.Request.Headers.Add(key, headers[key]);
}
}
if (this.Request.Method == HttpVerb.POST.ToString() && !String.IsNullOrEmpty(parameters))
{
var encoding = new UTF8Encoding();
var bytes = Encoding.GetEncoding("utf-8").GetBytes(parameters);
this.Request.ContentLength = bytes.Length;
using (var writeStream = Request.GetRequestStream())
{
writeStream.Write(bytes, 0, bytes.Length);
}
}
}
catch (Exception ex)
{
throw new ArgumentException(String.Format("Create WebRequest Error: {0}", ex.Message));
}
}
示例11: RestClient
public RestClient(string endpoint, HttpVerb method, string postData)
{
EndPoint = endpoint;
Method = method;
ContentType = "application/json";
PostData = postData;
}
示例12: WebRequestUtility
public WebRequestUtility(string realm, Uri requestUri, HttpVerb verb, Boolean keepAlive, String userAgent, NetworkCredential networkCredentials)
{
if (requestUri == null)
throw new ArgumentNullException("requestUri");
this.Realm = realm;
this.RequestUri = requestUri;
this.Verb = verb;
this.KeepAlive = keepAlive;
this.UserAgent = userAgent;
this.UseOAuth = false;
if (networkCredentials != null)
this.NetworkCredentials = networkCredentials;
this.Parameters = new Dictionary<string, object>();
if (string.IsNullOrEmpty(this.RequestUri.Query)) return;
foreach (Match item in Regex.Matches(this.RequestUri.Query, @"(?<key>[^&?=]+)=(?<value>[^&?=]+)"))
{
this.Parameters.Add(item.Groups["key"].Value, item.Groups["value"].Value);
}
this.RequestUri = new Uri(this.RequestUri.AbsoluteUri.Replace(this.RequestUri.Query, ""));
}
示例13: RestClient
public RestClient(string endpoint, string command, HttpVerb method)
{
_params = new Dictionary<string, string>();
EndPoint = endpoint;
Command = command;
Method = method;
ContentType = "text/xml";
PostData = string.Empty;
}
示例14: RestClient
public RestClient(string endpoint, HttpVerb method, string postData, string callType, string token)
{
EndPoint = endpoint;
Method = method;
ContentType = "application/json";
CallType = callType;
PostData = postData;
Token = token;
}
示例15: MakeRequest
public void MakeRequest(HttpVerb method, string url, HeaderProvider header, AuthenticationProvider auth, BodyProvider body)
{
this.method = method;
this.url = url;
this.headers = header;
this.auth = auth;
this.body = body;
this.MakeRequest();
}