Submit a form that is saved in a string (ASP.NET)? - c#

I have a HTML form a string variable.
e.g: there are below string in FormBody variable string.
<form id='paymentUTLfrm' action='...' method='post'>
<input type='hidden' name='CardAcqID' value='131211234234667' />
<input type='hidden' name='AmountTrans' value='1' />
<input type='hidden' name='ORDERID' value='1' />
<input type='hidden' name='TerminalID' value='1723429902234254' />
<input type='hidden' name='TimeStamp' value='1282408234231473657' />
<input type='hidden' name='FP' value='56-85-2E-A6-F4-4B-7F-AD-17-E1-D9-97-D5-40-62' />
<input type='hidden' name='RedirectURL' value='http://localhost:1903/Service1.asmx?op=MelliSale' />
<input type='hidden' name='MerchantAdditionalData' value='' />
<input type='hidden' name='Version' value='3.22' />
</form>
Now I wanna submit it via ASP.NET and C# !!!
Could you please guide me how I can do it ?

see this page
How to: Send Data Using the WebRequest Class
or do pablo answer

You need an HttpClient in C#. You can take a look at this MS support document with some help on how to do that or you can just use WebClient class.
With that Http Client, you will have to implement the POST HTTP command to send your data with application/x-www-form-urlencoded content type. That encoded data will contain each variable have in your string. To get their values, you will have to parse it.

Related

Payfort Integration with Asp.Net MVC from server side

Currently, We are assigning the values in the below form and post the data to payfort. Which works fine!!
<form method="post" action="https://sbcheckout.payfort.com/FortAPI/paymentPage" id=form1 name=form1>
<input type="hidden" name="signature" />
<input type="hidden" name="command" />
<input type="hidden" name="merchant_reference" />
<input type="hidden" name="amount" />
<input type="hidden" name="access_code" />
<input type="hidden" name="merchant_identifier" />
<input type="hidden" name="currency" />
<input type="hidden" name="language" />
<input type="hidden" name="customer_email" />
<input type="hidden" name="payment_option" />
<input type="hidden" name="order_description" />
<input type="hidden" name="return_url" />
But when we post the data throw above method it shows the credential information to others
Is there any way that we can post the data to payfort from our controller and redirect to posted URL ?
You can use: https://github.com/payfort/payfort-dotnet-sdk/
this is official dotnet SDK from payfort
Yes you can post data to payfort using .Net Client library https://github.com/payfort/start.net
steps to call payfort.
1) Generate card Token
pass open key and card detail.
2) create charge using card token
3) capture charge amount

How to pass custom data via PayPal IPN

I use following code for the RETURN URL.
#foreach (var item in Model)
{
<form action='#item.PayPalURL2 ' method='post'>
<input type='hidden' name='cmd' value='_xclick' />
<input type='hidden' name='business' value='#item.BusinessEmail' />
<input name='item_name' value='#item.Name' class="ppField" readonly="readonly"/>
<input type='hidden' name='item_number' value='#item.ID' />
<input name='amount' value='#item.Price2' class="ppField" readonly="readonly"/>
<input type='hidden' name='return' value='#item.ReturnURL' />
<input type='hidden' name='custom' value='#item.UserID' />
<input type='submit' value='Buy' />
</form>
}
Any clue how to pass custom filed to IPN message and get it via Listener?
Thank you!!!
You've already got the "custom" field included in your form. Whatever value you have in #item.UserID will be getting sent along with the payment and will come back as a POST value called "custom" within your IPN solution.
So, it looks like you're already got what you need. You just need to make sure $item.UserID actually contains what you expect it to contain, and that you're looking for the custom field in your IPN listener.

How to send data from one page to another page with querystring and input form?

I am working in C#(asp.net). I have two pages 'abc.aspx' and 'xyz.aspx'. I want to send data from 'abc.aspx' to 'xyz.aspx'. I am using this code.
In 'abc.aspx'
<form action='xyz.aspx?site=google&code=123' method='get'>
<input type='text' name='name1' />
<input type='submit' value='submit' />
</form>
Now, I want to access all three values (site,code and name1). But, in 'xyz.aspx', I got only one value i.e name1. How to get all three values.
You need to put the values into hidden <input /> elements and hard-code the values if you want to have them end up in the query string. You're correct in setting the method='get':
<form action='xyz.aspx' method='get'>
<input type='hidden' name='site' value='google' />
<input type='hidden' name='code' value='123' />
<input type='text' name='name1' />
<input type='submit' value='submit' />
</form>
I think this one is the best.
In abc.aspx
<form action="xyz.aspx?site=google" method="post">
<input type="text" name="name1" />
<input type="submit" value="Submit" />
</form>
In xyz.aspx, access the data like this..
string site = Request.QueryString["site"];
string name = Request.Form["name1"];
//Remaining code...

Reading parameters like signup[product][handle] in ASP.NET

I need to read parameters from Context.Request that is written in a format like:
url?event=open&signup[customer][first_name]=John&signup[customer][last_name]=Doe&signup[payment_profile][card_number]=xxxxxxxx
Is there an easy way to parse this into a c# object? Would it be recommended to parse this in to a NameValueCollection, or is it to complex?
I am not familiar with this way of posting data, I don't even know what it is called when you do it like this, anyone care to fill me in? Thanks!
In case you are interested, this is the way stuff get posted:
<form method="post" action="https://....">
<input type="hidden" name="signup[product][handle]" value="basic" />
<input type="text" name="signup[customer][first_name]" />
<input type="text" name="signup[customer][last_name]" />
<input type="text" name="signup[customer][email]" />
<input type="text" name="signup[payment_profile][first_name]" />
<input type="text" name="signup[payment_profile][last_name]" />
<input type="text" name="signup[payment_profile][card_number]" />
<input type="text" name="signup[payment_profile][expiration_month]" />
<input type="text" name="signup[payment_profile][expiration_year]" />
<input type="submit" value="Sign Up" />
</form>
You can parse the query string into a NameValueCollection this way:
var nvc = new NameValueCollection();
nvc.Add(HttpUtility.ParseQueryString(Request.Params));

fill 2 form one field in common with C#

I need to fill two forms on the same website, my issue is the field because they have the same name, e.g. the password field in both forms is passed, so how can I fill both?
<form action="post.php" method="post">
<input type="hidden" name="name" value="value" />
<input type="text" name="image" />
<input type="password" name="pass" size="10" tabindex="7" accesskey="Q" value="">
</form>
<form action="post2.php" method="post">
<input type="hidden" name="name" value="value" />
<input type="text" name="image" />
<input type="password" name="pass" size="10" tabindex="4" accesskey="P" value="">
</form>
the code to fill fields I'm using is this:
WebBrowser1.Document.GetElementById("pass").SetAttribute("value", stringpassword);
thanks
The id attribute specifies a unique id for an HTML element.
The id must be unique within the HTML document.
The id attribute can be used by a JavaScript (via the HTML DOM) or by CSS to make changes or style the element with the specified id.
And if your specified website is not following the standard Html practices then you should write your own custom
code to access those controls and fill them straight away. You can use Regex Or Xpath for accomplishing this purpose.

Categories