M
Manuel
Quick Question:
How do I make a POST (with variables) using the WebClient.UploadFile method?
Full Description of the question:
My goal:
1) Log into a website. This website has a login form like this:
<form ENCTYPE='multipart/form-data' action="thesite.asp" method="post">
<input type="text" name="UserName">
<input type="password" name="Password">
<input type="submit" value="Enter">
</form>
Notice that it sends the data as if it sent a file!
2) Maintain the web session and cookies.
3) Get a few pages.
My research so far:
a) I need to use the System.Net.WebClient object because of goal #2
b) I need to use the WebClient.UploadFile method to login.
The server is expecting a post like this:
Content-Length: 341
-----------------------------491299511942
Content-Disposition: form-data; name="UserName"
MyUserName
-----------------------------491299511942
Content-Disposition: form-data; name="Password"
MyPassword
The methods WebClient.UploadData and WebClient.UploadValues Post the data in
the form:
UserName=MyUserName&Password=MyPassword
I don't know what the server does internally but it doesn't recognize the
variables sent this way. My only guess is that it has to do with goal #1
My Question:
How do I post variables using the WebClient.UploadFile method?
How do I make a POST (with variables) using the WebClient.UploadFile method?
Full Description of the question:
My goal:
1) Log into a website. This website has a login form like this:
<form ENCTYPE='multipart/form-data' action="thesite.asp" method="post">
<input type="text" name="UserName">
<input type="password" name="Password">
<input type="submit" value="Enter">
</form>
Notice that it sends the data as if it sent a file!
2) Maintain the web session and cookies.
3) Get a few pages.
My research so far:
a) I need to use the System.Net.WebClient object because of goal #2
b) I need to use the WebClient.UploadFile method to login.
The server is expecting a post like this:
Content-Length: 341
-----------------------------491299511942
Content-Disposition: form-data; name="UserName"
MyUserName
-----------------------------491299511942
Content-Disposition: form-data; name="Password"
MyPassword
The methods WebClient.UploadData and WebClient.UploadValues Post the data in
the form:
UserName=MyUserName&Password=MyPassword
I don't know what the server does internally but it doesn't recognize the
variables sent this way. My only guess is that it has to do with goal #1
My Question:
How do I post variables using the WebClient.UploadFile method?