Web Forms :: Post Multiple Files To A Web Form With Httpwebrequest?

Jul 3, 2010

I have a web form on a web page like this:

<form method="post" action="http://poston.domain.com/" enctype="multipart/form-data"> <input type="hidden" name="function" value="somevalue"> <input type="text" name="username" value="somevalue2"> <input type="text" name="password" value="somevalue3"> <input type="file" name="picture"> <input type="text" name="pictto" value="0"> <input type="submit" value="Send"></form>

I can post all the required data to that form on that page by calling the following function:

Public function GetResult(ByVal File As Byte)) as stringDim request As HttpWebRequest = CType(WebRequest.Create("http://poston.domain.com), HttpWebRequest)request.Method = "POST"request.KeepAlive = TrueDim boundary As String = "-------------------------" + DateTime.Now.Ticks.ToString("x")Dim header As String = vbCrLf & "--" + boundary + vbCrLfDim footer As String = vbCrLf & "--" + boundary + vbCrLfrequest.ContentType = String.Format("multipart/form-data; boundary={0}", boundary)Dim contents As StringBuilder = New StringBuilder()contents.Append(vbCrLf)contents.Append(header)contents.Append("Content-Disposition: form-data; name=""function""" & vbCrLf)contents.Append(vbCrLf)<br/>contents.Append("functionname1")contents.Append(header)contents.Append("Content-Disposition: form-data; name=""username""" & vbCrLf)contents.Append(vbCrLf)contents.Append(myusername)contents.Append(header)contents.Append("Content-Disposition: form-data; name=""password""" & vbCrLf)contents.Append(vbCrLf)contents.Append(mypassword)contents.Append(header)contents.Append("Content-Disposition: form-data; name=""pictto""" & vbCrLf)contents.Append(vbCrLf)contents.Append("0")contents.Append(header) contents.Append("Content-Disposition: form-data; name=""picture""; filename=""Untitled.jpg""" + vbCrLf)contents.Append("Content-Type: image/jpeg" + vbCrLf)contents.Append(vbCrLf)Dim BodyBytes As Byte() = Encoding.UTF8.GetBytes(contents.ToString())Dim footerBytes As Byte() = Encoding.UTF8.GetBytes(footer)request.ContentLength = BodyBytes.Length + File.Length + footerBytes.LengthDim requestStream As Stream = request.GetRequestStream()requestStream.Write(BodyBytes, 0, BodyBytes.Length)requestStream.Write(File, 0, File.Length)requestStream.Write(footerBytes, 0, footerBytes.Length)requestStream.Flush()requestStream.Close()Dim ret As String = NewStreamReader(request.GetResponse.GetResponseStream).ReadToEndreturn retend function

View 1 Replies

Similar Messages:

C# - Using HttpWebRequest To POST To A Form On An Outside Server?

Jan 26, 2010

I am trying to simulate a POST to a form on an external server that does not require any authentication, and capture a sting containing the resulting page. This is what the form looks like:

<INPUT type="hidden" name="JSPName" value="GIN">


<INPUT type="text" name="Field1" size="30"
maxlength="60" class="txtNormal" value="">

This is what my code looks like:

ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "Field1=VALUE1&JSPName=GIN";
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://XXX/controller");
myRequest.Method = "POST";
myRequest.ContentType = "text/html";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
StreamReader reader = new StreamReader(newStream);
string text = reader.ReadToEnd();

Currently, the code returns "Stream was not readable".

View 2 Replies

C# - HttpWebRequest POST Adds A NULL Value To Form Variables

Jan 10, 2011

I am attempting to call a RESTful service using an HttpWebRequest object via POST. I am attempting to pass 1 variable with the Request body which contains a url encoded string. I see the request when it hits the server; however, it shows 2 form variables. The first is Form[null] and the second is my variable.I am attempting to locate the source of this NULL key; however, I cannot. Any ideas on how I may be able to remedy this since it's throwing issues when I attempt to use it with the Nancy web framework for .Net.


var request = WebRequest.Create("http://localhost:8888/RouteName") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";[code]...

View 1 Replies

Win Form Application Freeze On HttpWebRequest File Post

Sep 3, 2010

I have an application that will upload files from my client to a web server using HttpWebRequest (with the function suggested here: [URL]

My problem is that when the file (about 10 mb in size) is being posted the whole application freezes (e.g. "application is not responding" when I try to move the window).

Do I need to put the uploading in a separate thread, or is there any other simple way solve this?

View 2 Replies

Handle Multiple Forms Post Action Under A Parent Form For Same Aspx Page?

Jul 27, 2010

I have an asp.net application in which I have a parent form and in that on load I am adding sub forms dynamically having a submit image button..

When I am clicking the button of one form then I am able to read the hidden variables using request under parent form .But on clicking the second button the hidden variables of parent form are having null value although i have assign the value to them using context variables.

how can i handle mulitple form action for same page

View 2 Replies

Web Forms :: Using HttpWebRequest To Post Credentials To A Remote Website?

Aug 30, 2010

I have a php website with a login page containing username and password fields with the same exact html names. I would like to have a page in my ASP.NET page with a username and a password textbox field that sends the corresponding credentials to the php website using HttpWebRequest. How would I do that and how could I check the response to see if the authentication has been successful?

View 1 Replies

Using Multiple Form Tag And Post Them To Another Page?

Oct 7, 2010

I don't know it's even possible but I try to achieve to post data from one page to another using the second form.The problem is I need a form tag for the user interface containing callback panels etc. I want to put a second form with some hidden-field:

<form id="postForm" method="post" action="target.aspx">
<input type="hidden" id="id" />

I submit the form from javascript with jquery:


Is there a way access the value of the hidden field on the target page?

View 1 Replies

MVC :: EF Update Multiple Rows In One Form Post?

Dec 14, 2010

I am a seasoned desktop developer but I am new to MVC, EF and web development in general. I have been following the MVC Music Store tutorial but using my own database and project instead of the one from the tutorial.

My project is a web front end to a configuration database that lets us implement new Markets (a.k.a. Customers) for our IVR. For the View that allows the user to modify an existing Market I use a ViewModel class that has two properties. One property (clientData) is an EntityObject populated from a single row of the Client_Data table. The other property (callflowSeq) is a List of EntityObjects populated from about 40 rows of the Callflow_Sequence table.

The "Get" Edit method of the MarketsEditViewModel displays the Edit View fine but when I modify the data only the Client_Data table gets updated.

Here is my ViewModel:


Here are the Edit methods from my Controller:


Here is my View:


It seems that I can't use UpdateModel() to update the Callflow_Sequence table but I can't figure out how to do it manually.

View 12 Replies

How To Get Status Code Of A Post With HttpWebRequest

Apr 10, 2010

I'm trying to ping Google when my web site's sitemap is updated but I need to know which status code does Google or any other service returns. My code is below:

HttpWebRequest rqst = (HttpWebRequest)WebRequest.Create("http://search.yahooapis.com/ping?sitemap=http%3a%2f%2fhasangursoy.com.tr%2fsitemap.xml");
rqst.Method = "POST";
rqst.ContentType = "text/xml";
rqst.ContentLength = 0;
rqst.Timeout = 3000;

View 2 Replies

Multiple File Inputs / When Post Back Request Files Collection Is Always Empty?

Jan 5, 2011

I am using Asp.net and requirement specifies i use html input to post files to server rather than asp:fileupload.[ Reason : Add more html input file controls similar to CPanel file manager.(i.e) clicking on link adds another file input from which user can select another file*.But when ever i post back Request Files collection is always empty.*

<form method="post" enctype="multipart/form-data" action="documents.aspx">
<input type="file" name="attachment" id="attachment" onchange="validate(this)" />
<span class="none">Filename should be within (1-25) letters long. Can Contain only letters
& numbers</span>
<div id="moreUploads">
<div id="moreUploadsLink" style="display: none;">
<a href="javascript:addFileInput();">Attach another File</a></div>
<input type="submit" id="btnSubmit" />


var upload_number = 2;function addFileInput() {
try {
var fileUpload = document.getElementById("attachment");
var elemSpan = nextElement(fileUpload).cloneNode(true);
var elemDiv = document.getElementById("moreUploads");
var d = document.createElement("div");
var file = document.createElement("input");
file.setAttribute("type", "file");
file.setAttribute("id", "attachment" + upload_number);
file.setAttribute("onchange", "validate(this)");
} catch (err) { alert(err);}}

the validate(this) is a function that validates file types on client.When validation succeeds then the link to add more file inputs is enabled. Could someone throw somelight on this.

View 1 Replies

C# - Underlying Connection Closed On HttpWebRequest POST On Production Server?

Nov 23, 2010

I'm getting the "The underlying connection was closed: The connection was closed unexpectedly." error while trying to POST using the HttpWebRequest class on the production server, on my dev machine it works fine.

I originally tried using the WebClient class but I switched to the HttpWebRequest to try some of the suggestions I found while researching the issue (such as setting KeepAlive to false, PreAuthenticate true and ProtocolVersion to 1.0).

Since it's only happening on the production server, i'm guessing that it might have something to do with IIS.

Here's my code


If set the Target Framework (I used a new project for testing) to 2.0 (I didn't test every version of the framework) it works. I'm guessing that .net handles the security differently in .net 4.0.

View 3 Replies

Web Forms :: HttpWebRequest Form Authentication Not Getting Past Login Page?

Sep 3, 2010

I am trying to use HTTPWebRequest to login to a site and then retrieve the page after login. However, it seems as if I can't get past the login. I also investigated with Fiddler and tried mimicking Fiddler almost completely and still no luck.


View 2 Replies

Http Form Post As Https Form Post?

Jun 3, 2010

Is there a way to force a non-secure form post to be secure? I understand there are ways to automatically resolve an http URL as an https URL but with form posts, is this type of redirection too late? Will the posted data have already gone through the wire as plain text?

View 3 Replies

Web Forms :: How To Post Data From One Form To Other Form Using Cross-Page Technique

Jan 14, 2011

I have Master Page and ascx user controls in my application.

how would I use the Cross-Page technique using the @ PreviousPageType directive.

useful links or samples to achieve this.

I am trying to use the Page class that exposes a property named PreviousPage from my User Control.

View 3 Replies

Data Controls :: How To Post XML Data To Secured (SSL) Website Using HttpWebRequest

May 16, 2013

I am using HttpWebRequest to post XML data to SSL URL.

I am using .NET 4.0 and tried many things but nothing worked for me.

1. I have tried adding Cert using in request but it also fails.X509Certificate Cert

try {
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

X509Certificate Cert = null


View 1 Replies

File Upload With HttpWebRequest Doesn't Post The File

Jun 17, 2010

Here is my code to post the file. I use asp fileupload control to get the file stream.

HttpWebRequest requestToSender = (HttpWebRequest)WebRequest.Create [URL]
requestToSender.Method = "POST";
requestToSender.ContentType = "multipart/form-data";
requestToSender.KeepAlive = true;
requestToSender.Credentials = System.Net.CredentialCache.DefaultCredentials;
requestToSender.ContentLength = BtnUpload.PostedFile.ContentLength;
BinaryReader binaryReader = new BinaryReader(BtnUpload.PostedFile.InputStream);
byte[] binData = binaryReader.ReadBytes(BtnUpload.PostedFile.ContentLength);
Stream requestStream = requestToSender.GetRequestStream();
requestStream.Write(binData, 0, binData.Length);
HttpWebResponse responseFromSender = (HttpWebResponse)requestToSender.GetResponse();
string fromSender = string.Empty;
using (StreamReader responseReader = new StreamReader(responseFromSender.GetResponseStream()))
fromSender = responseReader.ReadToEnd();
XMLString.Text = fromSender;

In the page load of CrossPage.aspx i have the following code

NameValueCollection postPageCollection = Request.Form;
foreach (string name in postPageCollection.AllKeys)
Response.Write(name + " " + postPageCollection[name]);
HttpFileCollection postCollection = Request.Files;
foreach (string name in postCollection.AllKeys)
HttpPostedFile aFile = postCollection[name];
aFile.SaveAs(Server.MapPath(".") + "/" + Path.GetFileName(aFile.FileName));
string strxml = "sample";

I don't get the file in Request.Files. The byte array is created. What was wrong with my HttpWebRequest?

View 2 Replies

Web Forms :: Form Post Encoding?

Dec 27, 2010

Our problem is the following:

We have a website that processing products from various web shops! Users of these web shops can send products for our site what will store these products in our database. Users are sending in products through the post method of the form, and within the form the data is in hidden imput fields! Our site using UTF-8 charset, and this service is working like a charm together with other pages that has utf8 chaset too. The problem comes when someone using our service from a site that has other charset then utf8, for example: iso-8859-2.This case the special hungarian characters, like "íéáűőúöüó" are replaced with a '�' character!We have tried to convert the incoming string on server side but that case the '�' has been replaced by '?'. - still not acceptable :)

View 1 Replies

Web Forms :: Why Isn't Possible To Post Form From An Iframe

Aug 30, 2010

Why is it not possible to post my form from an iframe? The form in the iframe is the same as the form outside the iframe. I have put in the EnvableEvent Validation="true". It is not working.

View 6 Replies

Web Forms :: Post Form To Other Page?

Sep 23, 2010

I want to be able to post my form data to another page based on the result of a validation done on server (and not via javascript). As an example, let's say the user captures a customer number and then captures the phone number of the customer on page A. When the user clicks on the submit button, the page posts back. Then, in the button click event, I need to check in the database if the customer number exists. If it exists, I need to post the data to page B so that user can input the next information. If it does not, I need to stay on the first page and show an error message telling the user that the customer does not exists.

I do not want to use Response.Redirect cause that would mean that page B would lose the form data coming from page A. I know about crosspage postbacks but that just turn the problem the other way around (if I post directly to page B, how do I get back to page A with the form data and show the error message?)...I know about Server.Transfer too but I would like to avoid that method because I know there are down sides to it too...I tried setting the button target URL to page B after validating from the database but it does not automatically redirect to Page B, it still shows up Page A and then if you click again on the button you are taken to page B. I know I could setup a javascript to automatically call the click on the button to post the page the second time automatically to the Page B but I don't like that method (if the user has slow internet, he sees the page twice and once the user is on page B, he can't use the back button cause he would be automatically redirected back to Page B because of the script).So, is there a way to change the request target after the button's click code has been handled???

View 3 Replies

Web Forms :: Don't Want Form To Post With ENTER Key?

Sep 16, 2010

I have done much searching and tried capturing javascript keydown events and such but cannot seem to stop a form from posting upon the user typing the ENTER key. I am using VB with VS 2008 SP1 and .NET 3.5 SP1. However, the ENTER key should function properly within a textarea input. So I have refrained from placing the keydown event in the Body tag.So I have wired up keydown events in 6 <asp:textboxes> that use the AutoComplete Extender. The javascript called is:

function on_keydown(e) {
var keynum;
var keychar;
var numcheck;


View 8 Replies

Send Form Files To The Server Just To Get Summary Filesize Without Sending The Whole Files?

Dec 24, 2010

I have a form with 10 file inputs. They can contain 10 random files with random sizes. If I send these files to ASP.NET server with this code:

var count = HttpContext.Current.Request.Files.Count;
var TotalSize = 0;
for (int i = 0; i < count; i++ )
HttpPostedFile postedFile = HttpContext.Current.Request.Files.Get(i);
TotalSize += postedFile.ContentLength;

And as you can see I didn't save the files on the server, will this code just calculate the summary of files without need to receive the whole file from the client (And therefore it would be very fast)?

View 1 Replies

Web Forms :: Post Form To Web Service And Parse XML

Jan 10, 2011

Hope this is the right forum to ask. I am trying to write a simple mobile application with two form fields that POST to a webservice that queries an SQL database and comes back with an XML file that needs to be parsed and displayed
properly in a browser.

So what I have is a webservice .asmx file that is working properly and an HTML form that POST two variables to the webservice file. The result is the generated XML. I simply just need to know the simplest way to display parts of that data as output within the
design of the form page.

Here is the HTML form: http://www.bt4u.org/
And here is the web service: http://www.bt4u.org/BT4U/BT4U_WebService.asmx

If you enter in the following respectively you will see the XML file:


there is some sort of class that stores the XML in an array or some such thing that can then be manipulated

View 2 Replies

Web Forms :: Form Post And Button Click?

Apr 3, 2010

i m facing this problem for sum time now, and not found a solution yet.here it goes i have a webform on on which i have certain input fields,and a button trick here is i also want this form to connect to a payment gateway so i want this form to post some values to payment gateway, so on button click first it shouldsave the date and then post values and redirect user to payment gateway, during my tries i found out, it will only do one of the two if i specify form actiona and form method it will not save the data but directly redirect,which is not correct,i want both things to happen saving as well as post to payment gateway

View 9 Replies

Web Forms :: A Post From Web Form Got Lost. How To Track?

May 7, 2010

I work on a HR application for Internal people.One of my staff member is caliming that he applied for a job, but we do not have any entry in the database for applicants and no error in Log4net.

The staff member calims that he clicked on the Apply Button. And when we checked the IIS log we found one entry by that user in the IIS event viewer. Now how to determine if the person actaully clicked the apply now button or not.This is a serous issue for us as he is very upset as the Advertising for that position is taken off and he cannot apply now.

How to investigate? Also does IIS logs all POSTS and GET Requests?ur system Admin passed me an error log from the event viewer.Which is something like this:

2010-05-05 00:28:57 POST /HROnline/Recruitment/Apply.aspx rk=579&pid=0 8600 INTERNALMIISNY Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.1;+Trident/4.0;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.4506.2152;+.NET+CLR+3.5.30729


View 4 Replies

Web Forms :: Post A Form In .aspx Page To An External URL?

Sep 24, 2010

I'm migrating an old ColdFusion site to ASP.NET. One of the pages has a form that posts to an external URL.


I just discovered that you can't do this in an .aspx page. Seems the page will just post to itself if you hit the submit button.What's the proper technique for achieving this in ASP.NET? There are a couple of hidden fields that pass parameters to the external URL.

View 3 Replies

Copyrights 2005-15 www.BigResource.com, All rights reserved