Archived

This topic is now archived and is closed to further replies.

shehab

.net WPF web api using

Recommended Posts

when i try to connect with utorrent it only show results for html replying methods below is the code i'm using

------------------------------------------------------------------------------------------------------------------------------

WebClient client = new WebClient() { Credentials = new NetworkCredential("username", "password") };

StreamReader Reader = new StreamReader(client.OpenRead("http://localhost:" + "port" + "/gui/"));

-------------------------------------------------------------------------------------------------------------------------------

it replies with bad request for JSON based replying methods for example http://[iP]:[PORT]/gui/?list=1

any help :(

Share this post


Link to post
Share on other sites

There were two problems in my code

1. I didn't use the token from (http://localhost:port/gui/token.html)

2.the above request returned a cookie which i didn't save, so you have to keep the cookie with you.

Classes.CookieAwareWebClient client = new Classes.CookieAwareWebClient() { Credentials = new NetworkCredential("username", "password") };
StreamReader Reader = new StreamReader(client.OpenRead("http://localhost:" + "port" + "/gui/token.html"));
string token = HtmlRemoval.StripTagsRegexCompiled(Reader.ReadToEnd());
MessageBox.Show(token);
Reader = new StreamReader(client.OpenRead("http://localhost:" + "port" + "/gui/?list=1&token=" + token));
MessageBox.Show(Reader.ReadToEnd());

about the cookie aware web client it' an overridden class of web client you can find in the following link (http://stackoverflow.com/questions/1777221/c-using-cookiecontainer-with-webclient-class)

Share this post


Link to post
Share on other sites