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
Similar Messages:
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:
<FORM METHOD="POST" ACTION="/controller" NAME="GIN">
<INPUT type="hidden" name="JSPName" value="GIN">
Field1:
<INPUT type="text" name="Field1" size="30"
maxlength="60" class="txtNormal" value="">
</FORM>
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();
MessageBox.Show(text);
newStream.Close();
Currently, the code returns "Stream was not readable".
View 2 Replies
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.
Code:
var request = WebRequest.Create("http://localhost:8888/RouteName") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";[code]...
View 1 Replies
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
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);
requestStream.Close();
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";
Response.Clear();
Response.Write(strxml);
I don't get the file in Request.Files. The byte array is created. What was wrong with my HttpWebRequest?
View 2 Replies
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;
rqst.GetResponse();
View 2 Replies
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
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
[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
Jul 9, 2010
how to store into sql data base and and how to retriew xls file as xls file from database in the form form of byte[] using c# in asp.net application.
View 1 Replies
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
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.
[Code]....
View 2 Replies
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
[CODE]...
View 1 Replies
Feb 1, 2010
In my web application (ASP.NET) I have a block of code that uses HttpWebRequest to make a call to a REST service and continue execution. Right now it's taking longer than I would like to complete the full web request. The thing is that what the REST service returns isn't useful. Ideally I would like to send an Async web request to the REST service and then NOT wait for a response. The problem is that I've tried it out using request.BeginGetResponse(New AsyncCallback(AddressOf myFunc), Nothing)
To start an async request and instead of NOT waiting (which I would assume would be the default behavior of an async request) it continuously executes the callback function before executing the next line of code after BeginGetResponse.I'm suspecting that ASP.NET may convert it to a sync request when it's within a web application. I'm led to believe this because there's a IAsyncResult result object that is passed into the callback function and when I examine its CompletedSynchronously property it's always set to true.if it's possible to do an async HttpWebRequest (with no wait) from within an ASP.NET web application or is it always converted to a synchronous request?
View 2 Replies
Jul 15, 2010
what is the way to run asp.net forms like .exe file in Windows without any explorer
View 1 Replies
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
Oct 19, 2010
I am working on a .NET1.1 application. I want to download file on the web servers using httpwebresponse.
How to download a file on the webserver using httpwebresponse using C# code?
View 3 Replies
Jan 15, 2010
I need upload a file from a website to another website using WebClient or HttpWebRequest.
View 4 Replies
Jul 19, 2010
I need to delete all the item what I seleted or I Checked.so I collect all the ID I selected .
then what should I do next?I could not find a submit button to send them,they are not in a from.So I try to collect them to a JSON object and then use AJAX to send them to server.
View 4 Replies
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
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
Oct 5, 2010
Using Facebox with .NET (Web Forms) is painful--this primarily HTML site was designed by someone else. I may have IIS (7.5) issues as well. This Facebox pop-up is in a separate file, login.html, that is called from index.html:
$k('a[rel*=example_2]').facebox_1({
loading_image : '/images/loading.gif',
close_image : '/images/closelabel.gif'
});
and the link to open it
<a href="login.html" title="Log In" rel="example_2" id='login'>Log In </a>
The form to be submitted with username and password (login.html):
<form name="login" method="post" action="#" onsubmit="return false;">
and after it's validated (this is working), it posts to login.aspx (login.html):
[code]....
The form posts. I can debug it in Visual Studio in the Page_Load method of login.aspx. The last line of the Page_Load method is:
Response.Redirect("welcomepage.html");
But, the Facebox pop-up remains. Firebug shows the post, It hits the Page_Load method of login.aspx, and the Facebox pop-up doesn't go anywhere. BUT, Firebug shows welcomepage.html rendered twice in the Response tab of the XHR (huh? why XHR?) request. I thought $.post did a regular postback. And why isn't my browser actually redirecting.
Attempted Fix
If I change the form in login.html to action='login.aspx', I get a 405.0 error method not allowed (but, it's trying to post to index.html, HUH?). And I can't figure out how to fix this in IIS 7.5 on Windows 7. I get this error in Visual Studio and when deploying locally to IIS. I had read it may have to do with script mapping, handlers, or the fact that I'm posting from an but I can't find a sufficient fix.
View 1 Replies
Mar 28, 2011
I am trying out ASP.NET MVC2. I have a controller called SearchController and a view folder called Search containing Search.aspx. In my controller I have:
[code]....
In my view I have:
<form action="Search/Post" method="post">
<label><% Response.Write(Model.Title); %></label>
<input type="Submit" Value="First" Name="submitButton"/>
</form>
It works fine the first time I click the button, and the browser shows a url of [URL]. However, when I click the button a second time the browser url changes to [URL] and I get a 404. What am I doing wrong?
View 4 Replies
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
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" />
</form>
I submit the form from javascript with jquery:
$("#id").val(id);
$("#postForm").submit();
Is there a way access the value of the hidden field on the target page?
View 1 Replies
Mar 1, 2010
I have a single model type to wrap up various models I want to use in my view:
public class QuestionViewData {
public Question Question { get; set; }
public IList<Answer> Answers { get; set; }
}
Now, in my question view I pull the data from the Question object - that's fine. Secondly I iterate through all Answer objects and pass them to a partial view:
<% foreach(Answer item in Model.Answers) { %>
<% Html.RenderPartial("ShowAnswer", item); %>
<% } %>
For each answer (in the partial view) I have some action buttons (like ratings). I'm using separate form POST's with hidden fields for every button. The problem is that I can't post the whole QuestionViewData model to my action method cause I only have the Answer object as model in the partial view. However, I need to return the complete question view from that action that takes QuestionViewData as model.
View 2 Replies