I have an HTML file
<HTML>
<BODY>
<FORM name="form1" method="post">
<INPUT type = FILE name="image" action = http://localhost:61189/api/Utility" REQUIRED/>
<INPUT type = SUBMIT />
</FORM>
</BODY>
</HTML>
When Submitted it triggers the POST function of the APIController.
I want to get the image data to work on. Where in the Request can i get the image data ?
Well i found a way of entering data into HTML request using multi-part form request.
And C# provides good api to deal with such data.
Related
I want to use asp.net core Kestrel to make a simple server receive picture files from the html clients. I use an endpoint instead of a controller to get the target. Some browser have a size limit of posting the large url encoded string so I have to choose form-data rather than url-encoding. But I cannot receive any form-data in the server-side endpoint method:
client side:
<form id="form" action="/api/do" enctype="multipart/form-data" method="post">
<p>
<input type="file" id="file" accept="image/*" />
<input type="submit"/>
</p>
</form>
server side:
//register the endpoint
endpoints.MapPost("/api/do", Do);
.
.
.
async Task Do(HttpContext context)
{
var form = await context.Request.ReadFormAsync();
var file = form.Files[0];
....
}
The length of form.Files is always 0.
Must I use a controller?
Finally, I found what's wrong with the codes, I forgot to give a name of the "input element". If there is no name of the input element the browser will not submit it.
The Html Amp Post goes to the current url?.
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-form" rc="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
</head>
<body>
<form class="-amp-form" method="post" target="_top" novalidate="" action-xhr="/Home/About">
<input name="name" class="data-input" required="" type="text" placeholder="Name...">
<input name="email" class="data-input" required="" type="email" placeholder="Email...">
<input class="button button-primary" type="submit" value="Subscribe">
</form>
</body>
</html>
Hovering over the submit input button in a browser shows the current url and clicking the button appears to do nothing (using httpFiddler there is no post or get request occuring). The solution is a standard MVC 5 application with the layout changed to include the amp ⚡ symbol in Html declaration and scripts included. Any ideas why it would show the current url when hovering over the button for example https://localhost:44331/Home/Index and not make any posts with the above code when the form button is clicked?
here is one of the resources i have been following from: https://ampbyexample.com/components/amp-form/
The post was working, it just wasn't redirecting to the view after posting. The browser uses the 'action' property on the form to show the url that the user will be sent to and as this value is omitted for an amp action-xhr post it was just showing the current url; however it was still posting to the correct url when clicked. What i was looking to do is a post and redirect and it seems that currently only Get amp requests support page redirection. This might change in the future but for now it needs to use Get requests for page redirecting.
This is my first question to stackoverflow and I have been struggling with it for the past 2 days. I am working on asp.net mvc application and I m pretty new to it. I have a web app and now we are asked to add payment functionality to this app. from the service provider I got the url and they said its a post url and string format to send something like this.
Field1*45005L00|FName*Jonathan|LName*Barley|AmtDue*1570|
Post URL : https://www.sendpayments.com/Client/SSO/Home
the url is like this. So I m not sure how I need to proceed, so what i did was I did some research and found some code for sending a httpwebrequest. so I added a action method and added a form post action to the make payment button, which when clicked would go to the controller and invokes this sendrequest post method (the code I got from internet) however what happens is after I click on my button the code gets executed and I see a blank page with the following line on it. So not sure what is happening. The code is given here..do I need to do this from server or use jquery I m not sure at all. Please help.
System.Net.HttpWebResponse
public HttpWebResponse SendPostRequest(string data, string url)
{
data = "Field1*45005L00|FName*Jonathan|LName*Barley|AmtDue*1570|";
url = https://www.sendpayments.com/Client/SSO/Home;
//Data parameter Example
//string data = "name=" + value
HttpWebRequest httpRequest = (HttpWebRequest) HttpWebRequest.Create(url);
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.ContentLength = data.Length;
var streamWriter = new StreamWriter(httpRequest.GetRequestStream());
streamWriter.Write(data);
streamWriter.Close();
return (HttpWebResponse) httpRequest.GetResponse();
}
Text Recieved
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function BrowseBack() {
if (window.opener != undefined) {
window.close();
return;
}
history.back();
}
</script>
<link id="idStyleLink" rel="stylesheet" type="text/css" /><link runat="server" rel="icon1" href="images/favicon-med.ico" type="image/ico"/> <link runat="server" rel="icon" href="images/favicon-med.ico" type="image/x-icon"/><title>
</title></head>
<body class="td">
<form method="post" action="./error.aspx?aspxerrorpath=%2fCustomer%2fSingleSignOn%2fIndex" id="form1" autocomplete="off">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="1Rqce+RHGBAZPZKT4DCc7DjqgZIT89HQWlkNktl6sFzFbIvRvk1K/vcj1stkpDLFOCoCvo592mkFaJxGRVVR1Zacgtig9wQ5jOf0qkhv+zLw21ilQ4Grn0Y5mwp7OB+L59sLd/pRxCuqSCSKL23yD/9qIQPMfi0uf5CSCZjROpNEVkzBqOjRFD5WmgGU9gfC9x/xQZ0Yg+fNWua8EuFz7YIC1xVh5cZVX/wPP2wW4iuvTjZ+vvOS20qW3jvCvfjHMusdkgz2biY0wIbWbe3wOgUmHNHAKBEXC4nLincjvtcDbmcLTDcd7xePRd339YZb6Oz8MI2IBc5sZxZs3KENbSeo8IhokTmu5AUWsC+whXuIzJ1NPGiIOBehJNo3kSj847ZvYznsZJvZmvzZN7Kt3OHC0po=" />
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="AB827D4F" />
<input type="hidden" name="__VIEWSTATEENCRYPTED" id="__VIEWSTATEENCRYPTED" value="" />
<div id="Divdefaultmsg">
<b>We are sorry for this inconvenience but we are temporarily experiencing technical difficulties, if the problem persists, please contact Merchant Support at 877-981-3478.<br/>
</b>
</div>
<div>
<span id="Label1"></span>
<span id="lblerror"></span>
</div>
<br /> <div>
<a id="browseback" href="javascript:BrowseBack();">Back</a></div>
</form>
</body>
</html>
Update
Its a CashPro Biller Gateways Standard Single Sign On
Try changing the httpRequest.ContentType to "text/plain", or "text/plain; charset=UTF-8".
"application/x-www-form-urlencoded" is used for sending key-value pairs, so the server might be trying to interpret the data as such.
If that doesn't work try using the Postman Chrome plugin to experiment with sending data to the API. Try different combinations of inputs under the 'Body' tab until you find something that works. That should help you choose the correct ContentType.
The trailing | symbol in the data could also potentially be causing a type conversion issue on the server side too, but it's really hard to tell without more specific error info.
I have created a Webpage which will post as "post" method..not as "get" method.
<html>
<head>
</head>
<body>
<FORM action="RetrieveData_Post.asp" id=form1 method=post name=form1>
First Name:
<br>
<INPUT id="txtFirstName" name="txtFirstName" >
<br>
Last Name:
<br>
<INPUT id="txtLastName" name="txtLastName" >
<br>
<INPUT type="submit" value="Submit">
</FORM>
</body>
</html>
i want to retieve the values in the textboxes in the code behind of another form. Please help me.
You can access the form fields of a request in the HttpContext:
HttpContext.Current.Request.Form
or, to cover cookies, form, query string and server variables use either the Item or Params collection of the HttpRequest instance.
(In code behind, the Page base type has a Request property to avoid going via HttpContext.)
Change action="RetrieveData_Post.asp" to action="RetrieveData_Post.aspx" create the aspx page and use
HttpContext.Current.Request.Form
for retrive values.
I'm currently trying to implement something called 3d secure into our checkout system-
Implementing DataCash 3DSecure in C#
I've got most of the way there with it, however now, i'm having trouble creating an iFrame with the correct content in.
Basically, the user enters their credit card details, presses the "order" button and the page contacts the payment gateway (DataCash in our case)
If the card requires 3d secure authentication, a pareq (long message) is returned with a bunch of other stuff.
I've generated the page required, using this code:
HttpWebRequest / HttpWebResponse Base 64 problem
However, i need to implement this into an iFrame.
Here's how the documentation suggest doing it, but i cant seem to get it....
<html>
<head>
<title>Please Authenticate</title>
</head>
<body onload="OnLoadEvent();">
<form name="downloadForm" action="https://mybank.com/vbyv/verify" method="POST">
<input type="hidden" name="PaReq" value="AAABBBBCCCCHHHHHH=">
<input type="hidden" name="TermUrl" value="https:// www. MyWidgits.Com/next.cgi">
<input type="hidden" name="MD" value="200304012012a">
</form>
<script language="Javascript"> <!-- function OnLoadEvent() { document.downloadForm.target = "ACSframe"; document.downloadForm.submit(); } //--> </script>
<!-- MERCHANT TO FILL IN THEIR OWN BRANDING HERE -->
<iframe src="blank.htm" name="ACSframe" width="390" height="450" frameborder="0">
</iframe>
<!-- MERCHANT TO FILL IN THEIR OWN BRANDING HERE -->
</body>
</html>
I actually solved this as follows:
http://www.alexjamesbrown.com/blog/development/implementing-datacash-3d-secure-with-asp-net/