当前位置: 首页>>代码示例>>C#>>正文


C# RequestOptions类代码示例

本文整理汇总了C#中RequestOptions的典型用法代码示例。如果您正苦于以下问题:C# RequestOptions类的具体用法?C# RequestOptions怎么用?C# RequestOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RequestOptions类属于命名空间,在下文中一共展示了RequestOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDocumentCollection

        private static async Task<DocumentCollection> CreateDocumentCollection(DocumentClient client, Database database, string collectionId)
        {
            var collectionSpec = new DocumentCollection { Id = collectionId };
            var requestOptions = new RequestOptions { OfferType = "S1" };

            return await client.CreateDocumentCollectionAsync(database.SelfLink, collectionSpec, requestOptions);
        }
开发者ID:paulhoulston,项目名称:IssueTracker,代码行数:7,代码来源:DocumentDbCollection.cs

示例2: GetAsync

        public Task<object> GetAsync(string uri, Type type, RequestOptions requestOptions)
        {
            if (requestOptions != null)
                requestOptions.ResourceLoader = this;

            return this.loader.GetAsync(uri, type, requestOptions);
        }
开发者ID:Pomona,项目名称:Pomona,代码行数:7,代码来源:DefaultResourceLoader.cs

示例3: ClaimCreationWithClaimParamsObjectTest

        public void ClaimCreationWithClaimParamsObjectTest()
        {
            ClaimParams input = JsonConvert.DeserializeObject<ClaimParams>(ClaimInput);
            RequestOptions options = new RequestOptions();
            options.IsTest = true;

            ClaimResponse actualResponse = claim.Create(input, options);
            ClaimSuccessCheck(actualResponse.JsonResponse());
        }
开发者ID:balu-eligible,项目名称:eligible-CSharp,代码行数:9,代码来源:ClaimTests.cs

示例4: AssertRequestOptionCall

 private void AssertRequestOptionCall(Action<IRequestOptions> options,
                                      Action<HttpRequestMessage> assertions,
                                      string uri = "http://whatever")
 {
     var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
     var requestOptions = new RequestOptions();
     options(requestOptions);
     requestOptions.ApplyRequestModifications(requestMessage);
     assertions(requestMessage);
 }
开发者ID:Pomona,项目名称:Pomona,代码行数:10,代码来源:RequestOptionsTests.cs

示例5: IssueWebRequestAsync

        /// <summary>
        /// Issues the web request asynchronous.
        /// </summary>
        /// <param name="endpoint">The endpoint.</param>
        /// <param name="method">The method.</param>
        /// <param name="input">The input.</param>
        /// <param name="options">request options</param>
        /// <returns></returns>
        public async Task<Response> IssueWebRequestAsync(
            string endpoint, string query, string method, Stream input, RequestOptions options)
        {
            options.Validate();
            Stopwatch watch = Stopwatch.StartNew();
            UriBuilder builder = new UriBuilder(
                _credentials.ClusterUri.Scheme,
                _credentials.ClusterUri.Host,
                options.Port,
                options.AlternativeEndpoint + endpoint);

            if (query != null)
            {
                builder.Query = query;
            }
            
            Debug.WriteLine("Issuing request {0} to endpoint {1}", Trace.CorrelationManager.ActivityId, builder.Uri);
            HttpWebRequest httpWebRequest = WebRequest.CreateHttp(builder.Uri);
            httpWebRequest.ServicePoint.ReceiveBufferSize = options.ReceiveBufferSize;
            httpWebRequest.ServicePoint.UseNagleAlgorithm = options.UseNagle;
            httpWebRequest.Timeout = options.TimeoutMillis;
            httpWebRequest.KeepAlive = options.KeepAlive;
            httpWebRequest.Credentials = _credentialCache;
            httpWebRequest.PreAuthenticate = true;
            httpWebRequest.Method = method;
            httpWebRequest.Accept = _contentType;
            httpWebRequest.ContentType = _contentType;
            // This allows 304 (NotModified) requests to catch
            //https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.allowautoredirect(v=vs.110).aspx
            httpWebRequest.AllowAutoRedirect = false;

            if (options.AdditionalHeaders != null)
            {
                foreach (var kv in options.AdditionalHeaders)
                {
                    httpWebRequest.Headers.Add(kv.Key, kv.Value);
                }
            }

            if (input != null)
            {
                // expecting the caller to seek to the beginning or to the location where it needs to be copied from
                using (Stream req = await httpWebRequest.GetRequestStreamAsync())
                {
                    await input.CopyToAsync(req);
                }
            }

            var response = (await httpWebRequest.GetResponseAsync()) as HttpWebResponse;
            return new Response()
            {
                WebResponse = response,
                RequestLatency = watch.Elapsed
            };
        }
开发者ID:xumingxiang,项目名称:hbase-sdk-for-net,代码行数:63,代码来源:GatewayWebRequester.cs

示例6: ClaimCreationWithRequestOptionsTest

        public void ClaimCreationWithRequestOptionsTest()
        {
            RequestOptions options = new RequestOptions();
            options.IsTest = true;
            options.ApiKey = null;
            Hashtable input = JsonConvert.DeserializeObject<Hashtable>(ClaimInput);

            ClaimResponse actualResponse = claim.Create(input, options);

            ClaimSuccessCheck(actualResponse.JsonResponse());
        }
开发者ID:balu-eligible,项目名称:eligible-CSharp,代码行数:11,代码来源:ClaimTests.cs

示例7: ReadOrCreateCollection

        private static async Task ReadOrCreateCollection(string databaseLink)
        {
            Collection = Client.CreateDocumentCollectionQuery(databaseLink).Where(col => col.Id == _collectionId).AsEnumerable().FirstOrDefault();

            if (Collection == null)
            {
                var collectionSpec = new DocumentCollection {Id = _collectionId};
                var requestOptions = new RequestOptions {OfferType = "S1"};

                Collection = await Client.CreateDocumentCollectionAsync(databaseLink, collectionSpec, requestOptions);
            }
        }
开发者ID:christophla,项目名称:PerformanceSandbox,代码行数:12,代码来源:DocumentDb.cs

示例8: IssueWebRequestAsync

        /// <summary>
        /// Issues the web request asynchronous.
        /// </summary>
        /// <param name="endpoint">The endpoint.</param>
        /// <param name="method">The method.</param>
        /// <param name="query">The query.</param>
        /// <param name="input">The input.</param>
        /// <param name="options">request options</param>
        /// <returns></returns>
        public async Task<Response> IssueWebRequestAsync(
            string endpoint, string method, string query, Stream input, RequestOptions options)
        {
            options.Validate();
            Stopwatch watch = Stopwatch.StartNew();
            UriBuilder builder = new UriBuilder(
                _credentials.ClusterUri.Scheme,
                _credentials.ClusterUri.Host,
                options.Port,
                options.AlternativeEndpoint + endpoint);

            if (query != null)
            {
                builder.Query = query;
            }

            Debug.WriteLine("Issuing request {0} to endpoint {1}", Trace.CorrelationManager.ActivityId, builder.Uri);
            HttpWebRequest httpWebRequest = WebRequest.CreateHttp(builder.Uri);
            httpWebRequest.ServicePoint.ReceiveBufferSize = options.ReceiveBufferSize;
            httpWebRequest.ServicePoint.UseNagleAlgorithm = options.UseNagle;
            httpWebRequest.Timeout = options.TimeoutMillis;
            httpWebRequest.KeepAlive = options.KeepAlive;
            httpWebRequest.Credentials = _credentialCache;
            httpWebRequest.PreAuthenticate = true;
            httpWebRequest.Method = method;
            httpWebRequest.Accept = _contentType;
            httpWebRequest.ContentType = _contentType;

            if (options.AdditionalHeaders != null)
            {
                foreach (var kv in options.AdditionalHeaders)
                {
                    httpWebRequest.Headers.Add(kv.Key, kv.Value);
                }
            }

            if (input != null)
            {
                // seek to the beginning, so we copy everything in this buffer
                input.Seek(0, SeekOrigin.Begin);
                using (Stream req = httpWebRequest.GetRequestStream())
                {
                    await input.CopyToAsync(req);
                }
            }

            var response = (await httpWebRequest.GetResponseAsync()) as HttpWebResponse;
            return new Response()
            {
                WebResponse = response,
                RequestLatency = watch.Elapsed
            };
        }
开发者ID:thomasjungblut,项目名称:hbase-sdk-for-net,代码行数:62,代码来源:GatewayWebRequester.cs

示例9: ApiRequest

 public ApiRequest(RequestOptions options)
 {
     // BasicConfigurator.Configure();
     requestOptions = options;
     client = new RestClient(requestOptions.Url);
     request = new RestRequest();
     request.AddHeader("Content-Type", "application/json");
     request.AddHeader("X-Key", requestOptions.ApiKey);
     request.AddHeader("X-Password", requestOptions.Password);
     request.AddHeader("X-Dat-Channel", "link-dotnet");
     request.RequestFormat = DataFormat.Json;
 }
开发者ID:datil,项目名称:link-dotnet,代码行数:12,代码来源:ApiRequest.cs

示例10: UrlRequest

		private static async Task<HttpResponseMessage> UrlRequest(string request, HttpMethod httpMethod, Dictionary<string, string> data = null, Dictionary<string, string> cookies = null, string referer = null, RequestOptions requestOptions = RequestOptions.None) {
			if (string.IsNullOrEmpty(request) || httpMethod == null) {
				return null;
			}

			HttpResponseMessage responseMessage;
			using (HttpRequestMessage requestMessage = new HttpRequestMessage(httpMethod, request)) {
				if (data != null) {
					try {
						requestMessage.Content = new FormUrlEncodedContent(data);
					} catch (UriFormatException e) {
						Logging.LogGenericException(e);
						return null;
					}
				}

				if (cookies != null && cookies.Count > 0) {
					StringBuilder cookieHeader = new StringBuilder();
					foreach (KeyValuePair<string, string> cookie in cookies) {
						cookieHeader.Append(cookie.Key + "=" + cookie.Value + ";");
					}
					requestMessage.Headers.Add("Cookie", cookieHeader.ToString());
				}

				if (referer != null) {
					requestMessage.Headers.Referrer = new Uri(referer);
				}

				if (requestOptions.HasFlag(RequestOptions.FakeUserAgent)) {
					requestMessage.Headers.UserAgent.ParseAdd(FakeUserAgent);
				}

				if (requestOptions.HasFlag(RequestOptions.XMLHttpRequest)) {
					requestMessage.Headers.Add("X-Requested-With", "XMLHttpRequest");
				}

				try {
					responseMessage = await HttpClient.SendAsync(requestMessage).ConfigureAwait(false);
				} catch { // Request failed, we don't need to know the exact reason, swallow exception
					return null;
				}
			}

			if (responseMessage == null || !responseMessage.IsSuccessStatusCode) {
				return null;
			}

			return responseMessage;
		}
开发者ID:stregkoden,项目名称:ArchiSteamFarm,代码行数:49,代码来源:WebBrowser.cs

示例11: ListAllOrganizationQuotaDefinitions

 /// <summary>
 /// List all Organization Quota Definitions
 /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/195/organization_quota_definitions/list_all_organization_quota_definitions.html"</para>
 /// </summary>
 public async Task<PagedResponseCollection<ListAllOrganizationQuotaDefinitionsResponse>> ListAllOrganizationQuotaDefinitions(RequestOptions options)
 {
     UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget);
     uriBuilder.Path = "/v2/quota_definitions";
     uriBuilder.Query = options.ToString();
     var client = this.GetHttpClient();
     client.Uri = uriBuilder.Uri;
     client.Method = HttpMethod.Get;
     var authHeader = await BuildAuthenticationHeader();
     if (!string.IsNullOrWhiteSpace(authHeader.Key))
     {
         client.Headers.Add(authHeader);
     }
     var expectedReturnStatus = 200;
     var response = await this.SendAsync(client, expectedReturnStatus);
     return Utilities.DeserializePage<ListAllOrganizationQuotaDefinitionsResponse>(await response.ReadContentAsStringAsync(), this.Client);
 }
开发者ID:adasescu,项目名称:cf-dotnet-sdk-1,代码行数:21,代码来源:OrganizationQuotaDefinitions.cs

示例12: ButtonSend_Click

        protected async void ButtonSend_Click(object sender, EventArgs e)
        {

            RequestOptions requestOptions = null;
 
            //Request response in JSON format            
            requestOptions = new RequestOptions();
            requestOptions.Headers.Add("Accept", "application/json");

            //Send Request
            var response = await Global.HelloServiceClient.GetAsync(Uri + TextBoxName.Text, requestOptions);

            //Display result
            PanelResponse.Visible = true;
            LabelResponse.Text = response.Content.ReadAsStringAsync().Result;

        }
开发者ID:p102583trial,项目名称:RestBus.Examples,代码行数:17,代码来源:Default.aspx.cs

示例13: ListAllSpacesForDomainDeprecated

 /// <summary>
 /// List all Spaces for the Domain (deprecated)
 /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/195/domains__deprecated_/list_all_spaces_for_the_domain_(deprecated).html"</para>
 /// </summary>
 public async Task<PagedResponseCollection<ListAllSpacesForDomainDeprecatedResponse>> ListAllSpacesForDomainDeprecated(Guid? guid, RequestOptions options)
 {
     UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget);
     uriBuilder.Path = string.Format(CultureInfo.InvariantCulture, "/v2/domains/{0}/spaces", guid);
     uriBuilder.Query = options.ToString();
     var client = this.GetHttpClient();
     client.Uri = uriBuilder.Uri;
     client.Method = HttpMethod.Get;
     var authHeader = await BuildAuthenticationHeader();
     if (!string.IsNullOrWhiteSpace(authHeader.Key))
     {
         client.Headers.Add(authHeader);
     }
     var expectedReturnStatus = 200;
     var response = await this.SendAsync(client, expectedReturnStatus);
     return Utilities.DeserializePage<ListAllSpacesForDomainDeprecatedResponse>(await response.ReadContentAsStringAsync(), this.Client);
 }
开发者ID:adasescu,项目名称:cf-dotnet-sdk-1,代码行数:21,代码来源:DomainsDeprecated.cs

示例14: Get

 public static Response Get(string uri, RequestOptions options = null)
 {
     try
     {
         using (var client = new HttpClient())
         {
             var result = client.GetAsync(new Uri(uri)).Result;
             return new Response
             {
                 Content = result.Content,
                 StatusCode = result.StatusCode
             };
         }
     } catch(Exception exception) {
         throw exception;
     }
 }
开发者ID:nightgoat,项目名称:Requests,代码行数:17,代码来源:Request.cs

示例15: PrepareAndExecuteRequestAsync

        /// <summary>
        /// This request is used as a short-hand for create a Statement and fetching the first batch 
        /// of results in a single call without any parameter substitution.
        /// </summary>
        public async Task<ExecuteResponse> PrepareAndExecuteRequestAsync(string connectionId, string sql, uint statementId, long maxRowsTotal, int firstFrameMaxSize, RequestOptions options)
        {
            PrepareAndExecuteRequest req = new PrepareAndExecuteRequest
            {
                Sql = sql,
                ConnectionId = connectionId,
                StatementId = statementId,
                MaxRowsTotal = maxRowsTotal,
                FirstFrameMaxSize = firstFrameMaxSize
            };

            WireMessage msg = new WireMessage
            {
                Name = Constants.WireMessagePrefix + "PrepareAndExecuteRequest",
                WrappedMessage = req.ToByteString()
            };

            using (Response webResponse = await PostRequestAsync(msg.ToByteArray(), options))
            {
                if (webResponse.WebResponse.StatusCode != HttpStatusCode.OK)
                {
                    WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream());
                    ErrorResponse res = ErrorResponse.Parser.ParseFrom(output.WrappedMessage);
                    throw new WebException(
                        string.Format(
                            "PrepareAndExecuteRequestAsync failed! connectionId: {0}, Response code was: {1}, Response body was: {2}",
                            connectionId,
                            webResponse.WebResponse.StatusCode,
                            res.ToString()));
                }
                else
                {
                    WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream());
                    ExecuteResponse res = ExecuteResponse.Parser.ParseFrom(output.WrappedMessage);
                    return res;
                }
            }
        }
开发者ID:Azure,项目名称:hdinsight-phoenix-sharp,代码行数:42,代码来源:PhoenixClient.cs


注:本文中的RequestOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。