Thursday, 28 April 2016

Submitting form and post data dynamically in c#

No comments

here for sudopay api as example to post data instead of using form

from form - 

<form action="http://sandbox.sudopay.com/api/v1/merchants/11/websites/78/vaults/type/cc.json" method="post">
        <input name="user_handle" type="hidden" value="703212898983" />
        <input name="email" type="hidden" value="test@example.com" />
        <input name="credit_card_number" type="hidden" value="4111111111111111" />
        <input name="credit_card_expire" type="hidden" value="10/2016" />
        <input name="credit_card_type" type="hidden" value="visa" />
        <input name="credit_card_name_on_card" type="hidden" value="Fred" />
        <input name="email" type="hidden" value="test@example.com" />
        <input name="address" type="hidden" value="First Street" />
        <input name="city" type="hidden" value="Chennai" />
        <input name="state" type="hidden" value="Tamil Nadu" />
        <input name="country" type="hidden" value="IN" />
        <input name="buyer_ip" type="hidden" value="201.200.01.01" />
        <input name="zip_code" type="hidden" value="38005" />
        <input name="phone" type="hidden" value="9662542112" />
        <input name="success_url" type="hidden" value="https://sudopay.com//?pa=success#sudopay-demo" />
        <input name="cancel_url'" type="hidden" value="https://sudopay.com//?pa=failure#sudopay-demo" />
        <input name="submit" class="btn btn-large" type="submit" value="Pay $1" />
    </form>


instead from c# -

        private static System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
 static void Main(string[] args)
        {            
            Inputs.Add("user_handle", "009199199999199");
            Inputs.Add("email", "test@example.com");
            Inputs.Add("credit_card_number", "4111111111111111");
            Inputs.Add("credit_card_expire", "10/2016");
            Inputs.Add("credit_card_type", "visa");
            Inputs.Add("credit_card_name_on_card", "Fred");
            Inputs.Add("email", "test@example.com");
            Inputs.Add("address", "First Street");
            Inputs.Add("city", "Chennai");
            Inputs.Add("state", "Tamil Nadu");
            Inputs.Add("country", "IN");
            Inputs.Add("zip_code", "38005");
            Inputs.Add("phone", "9662542112");
            Inputs.Add("buyer_ip", "201.200.01.01");

            WebClient client = new WebClient();
            client.Headers.Add("Authorization", "Basic MTEzMzc6ZDNkMDhkOGI0YzNlY2NmOGI0ODg3ZDhmN2QxYTc3ZGYxNzY1ZGVkNQ==");
            byte[] response = client.UploadValues("http://sandbox.sudopay.com/api/v1/merchants/11/websites/78/vaults/type/cc.json", Inputs);
            string result = System.Text.Encoding.UTF8.GetString(response);
        }


here authorization key like "MTEzMzc6ZDNkMDhkOGI0YzNlY2NmOGI0ODg3ZDhmN2QxYTc3ZGYxNzY1ZGVkNQ==" can be get from fiddler 
goto tools and textwizard , enter username and password which will return base 64 encoded url use that as authentication