本文整理汇总了C#中RequestMethod类的典型用法代码示例。如果您正苦于以下问题:C# RequestMethod类的具体用法?C# RequestMethod怎么用?C# RequestMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestMethod类属于命名空间,在下文中一共展示了RequestMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteUrl
public static byte[] ExecuteUrl(string url, RequestMethod method = RequestMethod.Post, NameValueCollection Parameters = null)
{
using (var webClient = new WebClient())
{
try
{
if (RequestMethod.Post == method)
{
var resBytes = webClient.UploadValues(url, Parameters);
return resBytes;
}
else
{
var resBytes = webClient.DownloadData(url);
return resBytes;
}
}
catch (Exception e)
{
return null;
}
}
}
示例2: Create
public static RequestInfo Create(
RequestMethod method, string target, string uriTemplate, Dictionary<string, object> parameters,
string userAgent, Dictionary<string, string> headers, ContentType requestContentType,
ContentType responseContentType, TimeSpan cacheDuration,
int timeout, int retryCount,
Uri uri, string requestBody, IRequestFactory requestFactory)
{
var result = new RequestInfo
{
Target = target,
UriTemplate = uriTemplate,
AllowedRetries = retryCount,
Uri = uri,
Method = method,
UserAgent = userAgent,
_headers = new Dictionary<string, string>(headers ?? new Dictionary<string, string>()),
RequestBody = requestBody,
Parameters = new Dictionary<string, object>(parameters ?? new Dictionary<string, object>()),
CacheDuration = cacheDuration,
RequestContentType = requestContentType,
ResponseContentType = responseContentType,
Timeout = timeout
};
return result;
}
示例3: GetResponseFromWattRequest
private HttpWebResponse GetResponseFromWattRequest(Uri requestUrl, RequestMethod method, string postData = "")
{
try
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUrl);
httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
httpWebRequest.CookieContainer = _cookieJar;
httpWebRequest.UserAgent = "CSharp HTTP Sample";
httpWebRequest.KeepAlive = true;
httpWebRequest.Headers.Set("Pragma", "no-cache");
httpWebRequest.Timeout = 300000;
httpWebRequest.Method = method.ToString();
if (method == RequestMethod.Post)
{
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
byte[] bytes = Encoding.ASCII.GetBytes(postData);
httpWebRequest.ContentLength = bytes.Length;
Stream requestStream = httpWebRequest.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
}
return (HttpWebResponse)httpWebRequest.GetResponse();
}
catch
{
return null;
}
}
示例4: RestMethodAttribute
public RestMethodAttribute(string url, RequestMethod method = RequestMethod.Get, string accept = null, string contentType = null)
{
this.Url = url;
this.Method = method;
this.Accept = accept;
this.ContentType = contentType;
}
示例5: PrepareRequestData
public string PrepareRequestData(object parameters, RequestMethod method)
{
var result = string.Empty;
if (parameters == null)
{
return result;
}
if (method == RequestMethod.Post)
{
switch (ContentType)
{
case ContentType.Json:
return JsonConvert.SerializeObject(parameters);
case ContentType.Xml:
using (var sw = new System.IO.StringWriter())
{
var serializer = new XmlSerializer(parameters.GetType());
serializer.Serialize(sw, this);
return sw.ToString();
}
}
}
result = ((Dictionary<string, object>)parameters).Aggregate(
result,
(current, parameter) => current + (parameter.Key + '=' + parameter.Value.ToString() + '&'));
return result.Trim(new[] {'&'});
}
示例6: CreateHttpJsonRequest
/// <summary>
/// Creates the HTTP json request.
/// </summary>
/// <param name="self">The self.</param>
/// <param name="url">The URL.</param>
/// <param name="method">The method.</param>
/// <param name="metadata">The metadata.</param>
/// <param name="credentials">The credentials.</param>
/// <returns></returns>
public static HttpJsonRequest CreateHttpJsonRequest(object self, Uri url, RequestMethod method, JObject metadata,
ICredentials credentials)
{
var request = new HttpJsonRequest(url, method, metadata, credentials);
ConfigureRequest(self, new WebRequestEventArgs {Request = request.webRequest});
return request;
}
示例7: Map
public static Method Map(RequestMethod method)
{
Method mthd;
Enum.TryParse(method.ToString().ToUpperInvariant(), out mthd);
return mthd;
}
示例8: Request
public Request()
{
this.contentLength = 0;
this.contentType = MimeType.Default;
this.cookies = new CookieCollection();
this.hasEntityBody = false;
this.headers = new HeaderCollection();
this.isAuthenticated = false;
this.isLocal = false;
this.isSecureConnection = false;
this.keepAlive = false;
this.localEndPoint = null;
this.method = RequestMethod.Unknown;
this.protocolType = null;
this.protocolVersion = null;
this.rawMethod = null;
this.rawRequest = null;
this.rawUrl = null;
this.referrer = null;
this.remoteEndPoint = null;
this.requestData = new RequestDataCollection();
this.url = null;
this.userAgent = null;
this.userHostName = null;
}
示例9: WebRequestWrapper
public WebRequestWrapper(Uri uri, RequestMethod requestMethod, string contentType, ref CookieContainer cookieJar, string dataToPost = null)
{
this.Uri = uri;
this.RequestMeth = requestMethod;
this.ContentType = contentType;
this.CookieJar = cookieJar;
this.DataToPost = dataToPost;
}
示例10: PollServiceEventArgs
public PollServiceEventArgs(RequestMethod pRequest, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,UUID pId)
{
Request = pRequest;
HasEvents = pHasEvents;
GetEvents = pGetEvents;
NoEvents = pNoEvents;
Id = pId;
}
示例11: HtmlForm
public HtmlForm(RequestMethod method, string action, IDictionary<string, string> errors = null)
: base("form", null)
{
SetAttribut("name", "form");
SetAttribut("method", method.ToString());
SetAttribut("action", action);
SetAttribut("onsubmit", "return FormIsValid()");
_errors = errors;
}
示例12: BoxRequest
public BoxRequest(RequestMethod method, Uri hostUri, string path)
{
Method = method;
Host = hostUri;
Path = path;
HttpHeaders = new List<KeyValuePair<string, string>>();
Parameters = new Dictionary<string, string>();
}
示例13: RequestSetting
public RequestSetting(RequestMethod method, string url)
{
_protocolVersion = HttpVersion.Version11;
_method = method;
_url = url;
_accept = "text/html,application/xhtml+xml,*/*";
_userAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/6.0)";
}
示例14: Execute
public Stream Execute(string uri, NameValueCollection data, Dictionary<string, Stream> files, RequestMethod method = RequestMethod.POST)
{
String boundary = "SMSAPI-" + DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss") + (new Random()).Next(int.MinValue, int.MaxValue).ToString() + "-boundary";
WebRequest webRequest = WebRequest.Create(baseUrl + uri);
webRequest.Method = RequestMethodToString(method);
if (basicAuthentication != null)
{
webRequest.Headers.Add("Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(basicAuthentication.GetUsername() + ":" + basicAuthentication.GetPassword())));
}
if (RequestMethod.POST.Equals(method) || RequestMethod.PUT.Equals(method))
{
Stream stream;
if (files != null && files.Count > 0)
{
webRequest.ContentType = "multipart/form-data; boundary=" + boundary;
stream = PrepareMultipartContent(boundary, data, files);
}
else
{
webRequest.ContentType = "application/x-www-form-urlencoded";
stream = PrepareContent(data);
}
webRequest.ContentLength = stream.Length;
try
{
stream.Position = 0;
CopyStream(stream, webRequest.GetRequestStream());
stream.Close();
}
catch (System.Net.WebException e)
{
throw new ProxyException(e.Message, e);
}
}
MemoryStream response = new MemoryStream();
try
{
CopyStream(webRequest.GetResponse().GetResponseStream(), response);
}
catch (System.Net.WebException e)
{
throw new ProxyException("Failed to get response from " + webRequest.RequestUri.ToString(), e);
}
response.Position = 0;
return response;
}
示例15: CreateContext
/// <summary>
///
/// </summary>
/// <param name="requestUri"></param>
/// <param name="method"></param>
/// <param name="request"></param>
protected void CreateContext(Uri requestUri, RequestMethod method, out HttpJsonRequest request)
{
Guard.Assert(() => requestUri != null);
var metadata = new JObject();
request = HttpJsonRequest.CreateHttpJsonRequest(this, new Uri(requestUri.AbsoluteUri + Guid.NewGuid()),
method, metadata, Credentials);
ContextStorage.Add(request, SynchronizationContext.Current);
}