当前位置: 首页>>代码示例>>C#>>正文


C# WebClient.DownloadString方法代码示例

本文整理汇总了C#中WebClient.DownloadString方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.DownloadString方法的具体用法?C# WebClient.DownloadString怎么用?C# WebClient.DownloadString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WebClient的用法示例。


在下文中一共展示了WebClient.DownloadString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main()
    {
        const string videoUrl = "https://www.youtube.com/watch?v=6pIyg35wiB4";

        var client = new WebClient();
        var videoPageData = client.DownloadString(videoUrl);

        var encodedSignature = SignatureRegex.Match(videoPageData).Groups["Signature"].Value;

        var playerVersion = PlayerVersionRegex.Match(videoPageData).Groups["PlayerVersion"].Value;
        var playerScriptUrl = string.Format(PlayerScriptUrlTemplate, playerVersion);
        var playerScript = client.DownloadString(playerScriptUrl);

        var decodeFunctionName = DecodeFunctionNameRegex.Match(playerScript).Groups["FunctionName"].Value;
        var decodeFunction = Regex.Match(playerScript, DecodeFunctionPatternTemplate.Replace("#NAME#", decodeFunctionName)).Value;
        var helperObjectName = HelperObjectNameRegex.Match((decodeFunction)).Groups["ObjectName"].Value;
        var helperObject = Regex.Match(playerScript, HelperObjectPatternTemplate.Replace("#NAME#", helperObjectName)).Value;

        var engine = new ScriptEngine(ScriptEngine.JavaScriptLanguage);
        var decoderScript = engine.Parse(helperObject + decodeFunction);
        var decodedSignature = decoderScript.CallMethod(decodeFunctionName, encodedSignature).ToString();

        // Jint variant
        //var engine = new Engine();
        //var decoderScript = engine.Execute(helperObject).Execute(decodeFunction);
        //var decodedSignature = decoderScript.Invoke(decodeFunctionName, encodedSignature).ToString();

        Console.WriteLine("Encoded Signature\n{0}.\n{1}", encodedSignature.Split('.').First(), encodedSignature.Split('.').Last());
        Console.WriteLine();
        Console.WriteLine("Decoded Signature\n{0}.\n{1}", decodedSignature.Split('.').First(), decodedSignature.Split('.').Last());
        Console.ReadLine();
    }
开发者ID:Herrie82,项目名称:lune-tube,代码行数:32,代码来源:untitled.cs

示例2: FetchPreviewUrl

    public void FetchPreviewUrl()
    {
        string URI = "http://api.7digital.com/1.2/track/search?q=" + Artist + " " + Title + "&y&oauth_consumer_key=7d4vqmmnvjrt&country=GB&pagesize=2";
        WebClient webClient = new WebClient();
        string strXml = webClient.DownloadString(URI);
        webClient.Proxy = null;
        int ix = strXml.IndexOf("track id=\"") + 10;
        Id = strXml.Substring(ix).Split('"')[0];
        PreviewUrl = webClient.DownloadString("http://localhost/ogger/sample-class.php?trackid=" + Id).Trim(); //the response is another url

        ix = strXml.IndexOf("<image>") + 7;
        ImageUrl = strXml.Substring(ix).Split('<')[0].Replace(".jpg", "0.jpg");
    }
开发者ID:gudmojo,项目名称:rvkmusichackday,代码行数:13,代码来源:Song.cs

示例3: Page_Load

    protected void Page_Load( object sender, EventArgs e )
    {
        var client = new WebClient();
        var html = client.DownloadString( "http://www.cnblogs.com/" );

        var parser = new JumonyParser();
        var document = parser.Parse( html );

        var links = document.Find( "a[href]" );

        var baseUrl = new Uri( "http://www.cnblogs.com" );

        var data = from hyperLink in links
               let url = new Uri( baseUrl, hyperLink.Attribute( "href" ).Value() )
               orderby url.AbsoluteUri
               select new
               {
                 Url = url.AbsoluteUri,
                 IsLinkingOut = !url.Host.EndsWith( "cnblogs.com" ),
                 Target = hyperLink.Attribute( "target" ).Value() ?? "_self"
               };

        DataList.DataSource = data;
        DataBind();
    }
开发者ID:Ivony,项目名称:Jumony-Guide,代码行数:25,代码来源:links.aspx.cs

示例4: GetPageContents

 private static string GetPageContents(string url)
 {
     using (var client = new WebClient())
     {
         return client.DownloadString(url);
     }
 }
开发者ID:MatthewKing,项目名称:SkypeBot,代码行数:7,代码来源:YouTubeTitleAnnouncer.cs

示例5: DownloadData

    public void DownloadData()
    {
        string Symbol;
        string Name;
        string Bid;
        string Ask;
        string Open;
        string PreviousClose;
        string Last;
        DateTime date1;
        using (WebClient web = new WebClient())
        {
            string csvData = web.DownloadString(string.Format("http://finance.yahoo.com/d/quotes.csv?s=AAPL+ACH+BAB+DAL+DWSN+EXPE+FCF+GYRO+HFWA+INFY+LAKE+NATI+OFC+PCTY+SAND+VTA+WPPGY+XLV+YHOO+YUM&f=snbaopl1"));

            string[] rows = csvData.Replace("\r","").Split('\n');

            foreach (string row in rows)
            {
                if (string.IsNullOrEmpty(row)) continue;

                string[] cols = row.Split(',');

                Symbol = Convert.ToString(cols[0]);
                Name = Convert.ToString(cols[1]);
                Bid = Convert.ToString(cols[2]);
                Ask = Convert.ToString(cols[3]);
                Open = Convert.ToString(cols[4]);
                PreviousClose = Convert.ToString(cols[5]);
                Last = Convert.ToString(cols[6]);
                date1 = DateTime.Now;
                string symbol1 = Symbol.Replace("\"", "");
                obj.insertstock(symbol1, Name, Bid, Ask, Open, PreviousClose, Last, date1);
            }
        }
    }
开发者ID:AshokYaganti,项目名称:ASE-Project,代码行数:35,代码来源:stockdatatest.aspx.cs

示例6: ZIP

    private string ZIP(string City, string State)
    {
        //http://zipcode.org/city/OK/TULSA

        //WebClient Client = new WebClient();
        using (WebClient Client = new WebClient())
        {
            string[] html = Client.DownloadString("http://zipcode.org/city/" + State + "/" + City)
                .Split(new char[] { '>', '<', '/', '"', '=' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < html.Length; i++)
            {

                if (html[i].Contains("Area Code"))
                {
                    for (i = 800; i < html.Length; i++)
                    {

                        if (html[i].Contains("a href"))
                        {
                            return html[i+1]; // returns a zip for the area.
                        }
                    }
                }
            }
        }
        return null;
    }
开发者ID:hype-armor,项目名称:Fancy,代码行数:27,代码来源:LocateMe.cs

示例7: Main

    public static void Main(string[] args)
    {
        // API Key, password and host provided as arguments
        if(args.Length != 3) {
          Console.WriteLine("Usage: ApplicantTracking <key> <password> <host>");
          Environment.Exit(1);
        }

        var API_Key = args[0];
        var API_Password = args[1];
        var host = args[2];

        var url = "https://" + host + "/remote/jobs/active.json";

        using (var wc = new WebClient()) {

        //Attach crendentials to WebClient header
        string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(API_Key + ":" + API_Password));
        wc.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;

        JavaScriptSerializer serializer = new JavaScriptSerializer();

        var results = serializer.Deserialize<Job[]>(wc.DownloadString(url));

        foreach(var job in results) {
          //Print results
          Console.WriteLine(job.Title + " (" + job.URL + ")");
        }
          }
    }
开发者ID:applicant-tracking,项目名称:applicant_tracking_api,代码行数:30,代码来源:ApplicantTracking.cs

示例8: GetCategories

    /// <summary> 
    /// This function is used to get all the available
    /// categories of possible events
    /// </summary>
    /// <param name="key">Key required to make the API call</param>
    /// <returns>JSON in String Format containing all categories</returns> 
    public string GetCategories(string key)
    {
        String outputString = "";
        int count = 0;
        Category category = null;
        Categories categories = new Categories();
        using (WebClient wc = new WebClient())
        {

            string xml = wc.DownloadString("http://api.evdb.com/rest/categories/list?app_key=" + key);
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            XmlNodeList root = doc.GetElementsByTagName("category");
            count = root.Count;
            string json = JsonConvert.SerializeXmlNode(doc);
            JObject obj = JObject.Parse(json);
            int temp = 0;
            while (temp < count)
            {
                category = new Category();
                category.categoryID = (string)obj["categories"]["category"][temp]["id"];
                category.categoryName = (string)obj["categories"]["category"][temp]["name"];
                categories.categories.Add(category);
                temp++;
            }
            outputString = JsonConvert.SerializeObject(categories);
        }
        return outputString;
    }
开发者ID:ksm5629,项目名称:WebServices,代码行数:35,代码来源:Service.cs

示例9: method_0

 public void method_0()
 {
     try
     {
         string xml;
         using (WebClient webClient = new WebClient())
         {
             xml = webClient.DownloadString(this.string_1 + "/main.xml");
         }
         XmlDocument xmlDocument = new XmlDocument();
         xmlDocument.LoadXml(xml);
         XmlNodeList elementsByTagName = xmlDocument.GetElementsByTagName("repofile");
         XmlNodeList elementsByTagName2 = ((XmlElement)elementsByTagName[0]).GetElementsByTagName("information");
         foreach (XmlElement xmlElement in elementsByTagName2)
         {
             XmlNodeList elementsByTagName3 = xmlElement.GetElementsByTagName("id");
             XmlNodeList elementsByTagName4 = xmlElement.GetElementsByTagName("name");
             this.string_0 = elementsByTagName4[0].InnerText;
             this.string_2 = elementsByTagName3[0].InnerText;
         }
         XmlNodeList elementsByTagName5 = ((XmlElement)elementsByTagName[0]).GetElementsByTagName("category");
         foreach (XmlElement xmlElement2 in elementsByTagName5)
         {
             XmlNodeList elementsByTagName3 = xmlElement2.GetElementsByTagName("id");
             XmlNodeList elementsByTagName4 = xmlElement2.GetElementsByTagName("name");
             GClass2 gClass = new GClass2();
             gClass.string_1 = elementsByTagName4[0].InnerText;
             gClass.string_0 = elementsByTagName3[0].InnerText;
         }
     }
     catch
     {
     }
 }
开发者ID:ZelkovaHabbo,项目名称:NF3_Compilable,代码行数:34,代码来源:GClass0.cs

示例10: Main

    static void Main()
    {
        string url = "http://db.tt/90tky6ui";

        // For speed of dev, I use a WebClient
        WebClient client = new WebClient();
        string html = client.DownloadString(url);

        int index = html.IndexOf("<img onload");
        int srcIndex = html.IndexOf("src=", index);
        string pseudoLink = html.Substring(srcIndex + 5);
        string link = pseudoLink.Substring(0, pseudoLink.IndexOf('"'));
        //HtmlDocument doc = new HtmlDocument();
        //doc.LoadHtml(html);

        //// Now, using LINQ to get all Images
        //List<HtmlNode> imageNodes = null;
        //imageNodes = (from HtmlNode node in doc.DocumentNode.SelectNodes("//img")
        //              where node.Name == "img"
        //              && node.Attributes["class"] != null
        //              && node.Attributes["class"].Value.StartsWith("img_")
        //              select node).ToList();

        //foreach (HtmlNode node in imageNodes)
        //{
        //    Console.WriteLine(node.Attributes["src"].Value);
        //}
    }
开发者ID:skirov,项目名称:TA-WebServicesAndCloud,代码行数:28,代码来源:Program.cs

示例11: Main

    public static void Main(string[] args)
    {
        int len = args.Length;
          string[] links = new string[1];
          var c = new WebClient();

          if(len == 0)
        Console.Write(c.DownloadString("http://www.google.com")); // default
          else links = args;

          for (int i = 0; i < len; i++)
          	{
          	  string data = c.DownloadString(links[i]);
          	  Console.Write(data);
          	}
    }
开发者ID:n-sm,项目名称:qrs,代码行数:16,代码来源:wget-curl.cs

示例12: GetTimeFromDDG

    private DateTime GetTimeFromDDG()
    {
        //https://duckduckgo.com/?q=what+time+is+it
        WebClient wc = new WebClient();
        try
        {
            char[] separators = new char[] { '<', '>', '\\', '/', '|' };

            string timeisPage = wc.DownloadString("https://duckduckgo.com/html/?q=what%20time%20is%20it");
            timeisPage = timeisPage.Remove(0, timeisPage.IndexOf("\n\n\t\n\n\n\n            ") + 19);
            string[] timeisSplit = timeisPage.Split(separators, StringSplitOptions.RemoveEmptyEntries);
            string Time = timeisSplit[0].Remove(timeisSplit[0].Length - 5);
            DateTime result;
            if (DateTime.TryParse(Time, out result))
            {
                return result;//.ToString("t");
            }
            throw new Exception();
        }
        catch
        {
            return DateTime.Now;//.ToString("t");
        }
        finally
        {
            wc.Dispose();
            GC.Collect();
        }
    }
开发者ID:hype-armor,项目名称:Fancy,代码行数:29,代码来源:Time.cs

示例13: getPlayer

	//Gets the players information
    public static Player getPlayer(string name) {
		Player player = null;
		string endpoint = api + "/players/find?name=" + name + "&device_id=" + Util.getDeviceID ();

		string response = null;
		try {
			WebClient client = new WebClient ();
			response = client.DownloadString (endpoint);
		} catch(Exception e) {
			Debug.LogError ("creating player inside try catch");
			return ApiClient.createPlayer (name);
		}
		if (!response.Contains ("id")) {
			Debug.LogError ("creating player outside try catch");
			return ApiClient.createPlayer (name);
		}

		JObject json = JObject.Parse (response);
		player = new Player(
			(int)json["id"],
			(string)json["name"],
			(int)json["hifive_count"],
			(int)json["characters"],
			(int)json["powerup_lvl"]
		);
		return player;
	}
开发者ID:jmangel,项目名称:ZombieRunIV,代码行数:28,代码来源:ApiClient.cs

示例14: GetHttp

 public static SqlString GetHttp(SqlString url)
 {
     if (url.IsNull) return SqlString.Null;
     var client = new WebClient();
     client.Encoding = Encoding.UTF8;
     return client.DownloadString(url.Value);
 }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:7,代码来源:WebFunctions.cs

示例15: SendSms

    public string SendSms(List<string> mobiles)
    {
        using (var client = new WebClient())
        {
            try
            {
                string langCode = "1";
                if (Regex.IsMatch(Message, @"\p{IsArabic}+"))
                {
                    langCode = "2";
                }

                client.Headers.Add("content-type", "text/plain");
                string mobile=String.Join(",",mobiles.ToArray());
                string result = client.DownloadString(String.Format("http://brazilboxtech.com/api/send.aspx?username=smartksa&password=ksasmrt95647&language={0}&sender=NCSS&mobile={1}&message={2}",langCode, mobile, Message));
                if (result.StartsWith("OK"))
                {
                    return String.Empty;
                }
                return result;
            }
            catch (Exception ex)
            {

                return ex.Message;
            }

        }
    }
开发者ID:samercs,项目名称:NCSS,代码行数:29,代码来源:SMSSender.cs


注:本文中的WebClient.DownloadString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。