user6687838
user6687838

Reputation: 21

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

Upvotes: 2

Views: 2286

Answers (2)

Furqan Misarwala
Furqan Misarwala

Reputation: 1891

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);

Upvotes: 1

Adil
Adil

Reputation: 3268

You need to use something like Amount.ToString() as this content would eventually be string/encoded as part of POST body.

Upvotes: 0

Related Questions