473,657 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmatic HTTP Post returns Empty Form fields on ASPX Server Side

Using Winform app writing a HTTP Post using the following... on the
server side, I get no form fields. Request.Form.Al lKeys.Length = 0.

If I put the field/value paris in the URL I can use
Request["FieldName"] to retrieve the values,
but POST doesn't work.

There is NO Proxy... the only thing I can think is that ASP.NET is
somehow filtering out the page because I'm obviously not posting the
viewstate??? Seems like there was some setting for this, but I can't
recall what it is.
HttpWebRequest request = (HttpWebRequest )
HttpWebRequest. Create("http://localhost/test.aspx");
WebResponse response;

string commentField = "ABCD=123";

ASCIIEncoding encoding = new ASCIIEncoding() ;
byte[] data = encoding.GetByt es(commentField );
request.Method = "POST";
request.Content Type = "applicatio n/x-www-form-urlencoded";
request.Content Length = data.Length;
Stream stream = request.GetRequ estStream();
stream.Write(da ta, 0, data.Length);
stream.Close();
response = request.GetResp onse();
//SERVER SIDE, test.aspx page
Page_Load()
{
//BREAK POINT SET HERE>>>>
//Request.Form.Al lKeys returns nothing (0 length)
}
Mar 22 '08 #1
1 3684
"ERobishaw" <ER*******@gmai l.comwrote in message
news:4c******** *************** ***********@e23 g2000prf.google groups.com...
Using Winform app writing a HTTP Post using the following... on the
server side, I get no form fields. Request.Form.Al lKeys.Length = 0.

If I put the field/value paris in the URL I can use
Request["FieldName"] to retrieve the values,
but POST doesn't work.

There is NO Proxy... the only thing I can think is that ASP.NET is
somehow filtering out the page because I'm obviously not posting the
viewstate??? Seems like there was some setting for this, but I can't
recall what it is.
HttpWebRequest request = (HttpWebRequest )
HttpWebRequest. Create("http://localhost/test.aspx");
WebResponse response;

string commentField = "ABCD=123";

ASCIIEncoding encoding = new ASCIIEncoding() ;
byte[] data = encoding.GetByt es(commentField );
request.Method = "POST";
request.Content Type = "applicatio n/x-www-form-urlencoded";
request.Content Length = data.Length;
Stream stream = request.GetRequ estStream();
stream.Write(da ta, 0, data.Length);
stream.Close();
response = request.GetResp onse();
//SERVER SIDE, test.aspx page
Page_Load()
{
//BREAK POINT SET HERE>>>>
//Request.Form.Al lKeys returns nothing (0 length)
}
Viewstate won't impact this code. The request object is a lower level
object provided by the HttpContext that is present in any handler be that an
ASPX or ASHX etc.

I can't explain why AllKeys has a length of 0, your calling code looks good.
Have you tried the System.Net.WebC lient object instead. It handles a lot of
this stuff for you:-

NameValueCollec tion fields = new NameValueCollec tion();
WebClient client = new WebClient();
fields.Add("ABC D", "123");
String response = client.UploadVa lues("http://localhost/test.aspx", fields);

--
Anthony Jones - MVP ASP/ASP.NET
Mar 22 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2517
by: Tim Wade | last post by:
Does anyone have any ideas on how to do an automatic html form post using hidden fields without introducing client-side script nor using a server-side WebRequest by passing the information back up to the browser while the base href is still set to my site. The problem I was having with the server-side WebRequest is that the relative links of the site I am posting to break. I could work my way around it probably by adding a base ref in the...
0
1275
by: KathyB | last post by:
Hi, I would be grateful for any guidance in how to achieve the following. I have an aspx page in which I transform an xmlDocument instance to the browser...so (as I understand it) that page contains the xmlDocument AND the transformed instance client-side in the browser. The main xml element used in this doc is a <step> element. For each step element I will create an "Anomaly" button using xsl to create an <input> button in html and...
19
2108
by: Bill Cohagan | last post by:
I'm constructing an ASP page that I'd like to test by writing a program that simulates "many" users hitting the submit button on a form. I assume it's possible to manually construct an httprequest object, but the docs are more oriented towards using one that already exists. Am I on the right track or is there an easier way? In my case the Form to be submitted has a couple of hundred fields and what I want to do is access a database with...
10
1843
by: Mark | last post by:
Hi All, I could do with some assistance... I am working on an ecommerce site in vb.net (aspx) I have built all my pages that perform the checkout process and gets to a summary screen where you check your data prior to making payment. The problem I have is that the external payment provider requires that I POST (GET is not allowed) the data to them where there site takes over and when complete returns back to the my site.
15
4596
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
7
1612
by: cindy | last post by:
I have a System.Web.UI.HtmlControls.HtmlInputFile control that I use to submit files. Before the file is successfully submitted I validate another field on the form, it is the description of the file must be 500 characters. I am adding the file to a site server library programmatically so if the field is too long I want to return the user to the form with file still selected in the HtmlInputFile control. I am using an error label to inform...
2
6299
by: MDANH2002 | last post by:
Hi From VB.NET I want to simulate the POST request of the following HTML form <html> <title>HTTP Post Testing</title> <body> <form action=http://www.example.com/postdata enctype="multipart/form-data" method="post" name="testform">
4
2225
by: CindyH | last post by:
Hi: I have the following code: Dim url As String = "http://xx01xx01:800/some.ashx" Dim myrequest As System.Net.WebRequest = Nothing Dim myresponse As System.Net.WebResponse = Nothing 'Prepare web request myrequest = System.Net.WebRequest.Create(url) 'use POST
6
3880
by: CindyH | last post by:
Hi I'm not sure whether I should send this as a new message or use the one I've been using but... I'm using vb.net 2.0 - My problem is I need to send something like this: 'dim encodedstring = "test=" + httputility.urlencode(doc.outerxml)' as a http xml post and then need to receive it on other end for a test. It needs to be sent as a stream. I need some sample code on how to post it and then receive the request on
0
8821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8502
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7316
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.