简体   繁体   中英

pass integer to FormUrlEncodedContent

i use asp.net mvc and c#, i my bank setion project i use this code for banking

var requestContent = new FormUrlEncodedContent(new[] {

    new KeyValuePair<string, string>("amount", payment.Amount), //i want change this section for <string,int>
    new KeyValuePair<string, string>("transid", "id"),
    new KeyValuePair<string, string>("pin","pin" )

});

var client = new HttpClient();

HttpResponseMessage response = await client.PostAsync("http://address.com/api/verify/", requestContent);

HttpContent responseContent = response.Content;

string result = "";

using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
    result = await reader.ReadToEndAsync();
}

now my bank scenario is change and i should pass integer for amount,how i can do i from mycode? because FormUrlEncodedContent accept <string,string> thank you for your help

您需要使用 Amount.ToString() 之类的东西,因为此内容最终将作为 POST 正文的一部分进行字符串/编码。

Try this, It is working for me.

        public class PaymentActionsRequest
        {
            [JsonProperty("payment_intent")]
            public string PaymentIntent { get; set; }
            
            [JsonProperty("amount")]
            public long Amount { get; set; }        
        }

      var keyValueContent = PaymentActionsRequest.ToKeyValue();
      var formUrlEncodedContent = new FormUrlEncodedContent(keyValueContent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM