tags:

views:

38

answers:

2

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  A: 

To login, you should probably use WebClient.UploadValues instead, as described here.

Andrei
What is the difference between that and string? i prefer not to convert the results from an array to a string :x
acidzombie24
UploadValues sets "content-type" header to "application/x-www-form-urlencoded", while UploadString does not specify content type. If you set this header explicitly, UploadString works just as UploadValues -- the string gets parsed by server as key=value pairs.
Andrei
A: 

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
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)
acidzombie24
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