3

What does WebClient.UploadString do?

I thought it post so i can login with it. When i used wc.UploadString(@"http://mysite.com/login", "user=u&pass=p"); i thought i would get the html of the front page with me logged in. However all i got was no warning that my pass was incorrect and my method=post note at the bottom.

What does WebClient.UploadString really do? and how can i login with WebClient?

1 Answers1

1

The second parameter is passing data in the post body. You've formatted it to be part of the querystring. If the username/password are really passed in the querystring they should be included in the first parameter (the url). Otherwise, which is more likely, if they are to be sent as form parameters, then use UploadValues as Andrei suggested.

Frank Schwieterman
  • 24,142
  • 15
  • 92
  • 130
  • Its a login. Where do i put it? I think this server requires it to be in post (i know some servers dont care if post data are in get queries) –  Jul 14 '10 at 21:44
  • POST is better. Log in through a web browser and do a network trace to see where it should be put. (For Firefox, you can use HttpFox plugin to monitor net traffic). – Frank Schwieterman Jul 14 '10 at 22:23