By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,356 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,356 IT Pros & Developers. It's quick & easy.

WebClient/POST/aspx file

P: n/a
Hi folks! I tried to post a web form using the WebClient class and
HttpWebRequest/HttpWebResponse. It didn't work for the ASPX web pages. I
always got an unposted version - like if I had just made a simple request
without posting anything. I have written the same thing using the Perl's
LWD::UserAgent class and it was the same. The web form is really very
simple. As soon as I created the ASP file with the same form everything
worked! Does anyone has an explanation? I have Framework 1.0 installed. The
only thing that I think can cause trouble is the viewstate. The code samples
are bellow.



<form id="WebForm1" method="post" runat="server">
if (Page.IsPostBack)

<input type="text" name="abc" value="">
<input type="submit" name="foo" value="bar">


System.Net.WebClient wc = new System.Net.WebClient();
System.Collections.Specialized.NameValueCollection values = new
System.Collections.Specialized.NameValueCollection ();

values.Add("abc", "123");
values.Add("foo", "bar");

byte[] dataBuffer = wc.UploadValues(http://localhost/WebForm1.aspx,"POST",

textBox1.Text = System.Text.Encoding.Default.GetString(dataBuffer) ;

use strict;
use LWP::UserAgent;
use HTTP::Request::Common;

my $ua = new LWP::UserAgent;
my $res = $ua->request(POST "http://localhost/WebForm1.aspx", [foo => "bar",
abc => "123"]);

if ($res->is_success) {
print $res->content;
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
I solved my problem after I started a HTTP sniffer. I saw the exact post
data the form was sending and after I copied the name/value pairs and sent
them using the UploadData method everything worked- so now I can
automatically configure some stuff on the firewall using the Web interface


Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.