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


C# FormUrlEncodedContent.ToString方法代码示例

本文整理汇总了C#中System.Net.Http.FormUrlEncodedContent.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# FormUrlEncodedContent.ToString方法的具体用法?C# FormUrlEncodedContent.ToString怎么用?C# FormUrlEncodedContent.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.FormUrlEncodedContent的用法示例。


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

示例1: SaveCreditCardInfo

        /// <summary>
        /// The save credit card info.
        /// </summary>
        /// <param name="creditCardInfo">The credit card info.</param>
        /// <param name="userId">the user id.</param>
        /// <returns>
        /// The <see>
        ///         <cref>AsyncCallResult</cref>
        ///     </see>
        ///     .
        /// </returns>
        public AsyncCallResult<string> SaveCreditCardInfo(CreditCardInfo creditCardInfo, string userId)
        {
            var source = new CancellationTokenSource();
            CancellationToken token = source.Token;
            string response = "Connection Timeout";
            TransactionTypes transactionType = TransactionTypes.AddCreditCard;
            using (
                var contents =
                    new FormUrlEncodedContent(
                        new List<KeyValuePair<string, string>>
                            {
                                new KeyValuePair<string, string>(
                                    "redirect_url", 
                                    this.redirectURI), 
                                new KeyValuePair<string, string>(
                                    "api_login", 
                                    this.securityKeys.Credentials.UserName), 
                                new KeyValuePair<string, string>(
                                    "credit_card[number]", 
                                    creditCardInfo.CreditCardNumber), 
                                new KeyValuePair<string, string>(
                                    "credit_card[month]", 
                                    creditCardInfo.CreditCardMonth.ToString()), 
                                new KeyValuePair<string, string>(
                                    "credit_card[year]", 
                                    creditCardInfo.CreditCardYear.ToString()), 
                                new KeyValuePair<string, string>(
                                    "credit_card[verification_value]", 
                                    creditCardInfo.CrediCardCVV.ToString()), 
                                new KeyValuePair<string, string>(
                                    "credit_card[first_name]", 
                                    creditCardInfo.FirstName), 
                                new KeyValuePair<string, string>(
                                    "credit_card[last_name]", 
                                    creditCardInfo.LastName)
                            }))
            using (var handler = new HttpClientHandler { AllowAutoRedirect = false, PreAuthenticate = false })
            using (var client = new HttpClient(handler))
            {
                const string URI = "https://spreedlycore.com/v1/payment_methods";
                string request = contents.ToString();
                using (Task<HttpResponseMessage> task = client.PostAsync(URI, contents, token))
                {
                    try
                    {
                        if (task.Wait(20000, token) == false)
                        {
                            if (token.CanBeCanceled)
                            {
                                source.Cancel();
                            }

                            this.LogToDb(userId, request, response, transactionType);
                            return new AsyncCallResult<string>(AsyncCallFailureReason.TimeOut);
                        }
                    }
                    catch (Exception ex)
                    {
                        request = "Connection Failure, error : - " + ex;
                        this.LogToDb(userId, request, response, transactionType);
                        return new AsyncCallResult<string>(AsyncCallFailureReason.FailedConnection);
                    }

                    if (task.Result.StatusCode != HttpStatusCode.Redirect)
                    {
                        request = "Connection Failure";
                        this.LogToDb(userId, request, response, transactionType);
                        return new AsyncCallResult<string>(
                            AsyncCallFailureReason.FailedStatusCode,
                            task.Result.Content.ReadAsStringAsync().Result);
                    }

                    response = task.Result.Content.ToString();
                    this.LogToDb(userId, request, response, transactionType);
                    return new AsyncCallResult<string>(
                        AsyncCallFailureReason.None,
                        task.Result.Headers.Location.Query.Substring(1));
                }
            }
        }
开发者ID:fishonline,项目名称:API-1,代码行数:91,代码来源:SpreedlyService.cs


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