Jump to content

.net WPF web api using


shehab

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

Link to comment
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)

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...