Пример #1
0
        public static void get_token(string ip, string port, string username, string password)
        {
            ///READ TOKEN
            string base_url = "http://" + ip + ":" + port + "/gui/";

            string token            = null;
            string token_urlAddress = base_url + "token.html";

            MainWindow.CookieAwareWebClient client = new MainWindow.CookieAwareWebClient()
            {
                Credentials = new NetworkCredential(username, password)
            };

            StreamReader Reader     = new StreamReader(client.OpenRead(token_urlAddress));
            string       read_token = Reader.ReadToEnd();

            token = Regex.Replace(read_token, "<.*?>", String.Empty);
            ///SEND TORRENT FILE
            string sURL = base_url + "?action=add-file";

            client.Headers.Add("Content-Type", "multipart/form-data");

            var reqparm = new System.Collections.Specialized.NameValueCollection();

            byte[] bytes = System.IO.File.ReadAllBytes("one.torrent");
            reqparm.Add("torrent_file", bytes.ToString());

            byte[] responsebytes = client.UploadData(sURL, "POST", Encoding.Default.GetBytes(reqparm.ToString()));//Encoding.Default.GetBytes("{'file' : 'torrent_file' : 'one.torrent'}"));
            string responsebody  = Encoding.UTF8.GetString(responsebytes);

            Debug.WriteLine(responsebody);
        }
Пример #2
0
        public static void send_magnet_uri(string ip, string port, string username, string password, string magnet)
        {
            string base_url = "http://" + ip + ":" + port + "/gui/";

            ///READ TOKEN
            string token_urlAddress = base_url + "token.html";

            MainWindow.CookieAwareWebClient client = new MainWindow.CookieAwareWebClient();
            client.Credentials = new NetworkCredential(username, password);

            client.OpenRead(token_urlAddress);

            StreamReader Reader = new StreamReader(client.OpenRead(token_urlAddress));
            string       token  = Reader.ReadToEnd();

            token = Regex.Replace(token, "<.*?>", String.Empty);
            ///SEND MAGNET LINK
            string add_url = base_url + "?action=add-url&s=" + WebUtility.UrlEncode(magnet) + "&token=" + token;

            client.OpenRead(add_url);
        }