WebClient/POST/aspx file

A

Adnan Selimovic

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.

Thanks,

Adnan

<form id="WebForm1" method="post" runat="server">
<%
if (Page.IsPostBack)
{
Response.Write("foobar");
}
%>

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

</form>

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",
values);

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;
}
 
A

Adnan Selimovic

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
hehe.

Bye,

Adnan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top