WebRequest/WebResponse OR WebClient problem

N

Nurchi BECHED

Hello, everyone.

I am stuck with the following:
There is a webpage which contains a webform, which
contains text fields, and submits the data from current
page to another one.

I need to submit the same data to a webpage from a
Windows Form.

I am playing with WebClient's UploadValues(...) method

I've also tried
HttpWebRequest
wrq=(HttpWebRequest)WebRequest.Create("http://localhost/mail.php");
<some code here>
And then HttpWebResponse wrs=(HttpWebResponse)wrq.GetResponse();

Nothing. I've tried that on my webserver, and it throws an exception with
error 403 from the
server, FORBIDDEN.

localhost/sendmail.php contains:
<form name="f1" action="mail.php" method="post">
<table>
<tr>
<td align="left" valign="top">
Your name:
</td>
<td align="left" valign="top">
<input type="text" name="sender" size="50">
</td>
</tr>
etc.................OTHER TEXT FIELDS
<tr>
<td align="left" valign="top">
<input type="submit" value="Send email">
</td>
<td align="left" valign="top">
&nbsp;
</td>
</tr>
</table>
</form>

localhost/mail.php receives POST'ed data from localhost/sendmail.php and
imails it me
(basically to prevent people/webrobots from seeing my email, so that I don't
get spam).
Works just fine.

But I need to submit (POST) data from a Windows form.
Thanks.
Any help is appreciated.

Regards, Nurchi
 
N

Nicholas Paldino [.NET/C# MVP]

Nurchi,

Are you making sure that you are passing the appropriate credentials as
well as cookies (stored locally as well as any that are set by the initial
download of the page)? Web applications more often than not depend heavily
on cookie state to be set correctly, as well as credential information to be
set in order to produce the desired result. When using the
HttpWebRequest/HttpWebResponse or the WebClient classes, you have to make
sure that you are setting things like the cookies, the user agent (web
applications will make decisions on what is rendered, and possibly other
pertinent information is sent back based on this), etc, etc.

In the end, make sure you are going through the appropriate steps
(loading the first page, collecting cookies, then following through to the
next page where you submit the information, etc, etc), as you use these
classes.

Hope this helps.
 

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

Top