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


C# WebClient.DownloadStringTaskAsync方法代码示例

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


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

示例1: DownloadQueue

		public async Task<Queue> DownloadQueue()
		{
			using (WebClient w = new WebClient())
			{
				return this.ConvertApiResultToQueue(await w.DownloadStringTaskAsync("http://localhost:8080/sabnzbd/api?mode=queue&output=xml"));
			}
		}
开发者ID:CSharpFan,项目名称:SABnzbd.UI,代码行数:7,代码来源:Connector.cs

示例2: GetVersion

        public async override Task<IEnumerable<string>> GetVersion(string packageName)
        {
            if (string.IsNullOrEmpty(packageName))
                return Enumerable.Empty<string>();

            string url = $"http://registry.npmjs.org/{packageName}";
            string json = "{}";

            using (var client = new WebClient())
            {
                json = await client.DownloadStringTaskAsync(url);
            }

            var array = JObject.Parse(json);
            var time = array["time"];

            if (time == null)
                return Enumerable.Empty<string>();

            var props = time.Children<JProperty>();

            return from version in props
                   where char.IsNumber(version.Name[0])
                   orderby version.Name descending
                   select version.Name;
        }
开发者ID:yannduran,项目名称:PackageInstaller,代码行数:26,代码来源:Npm.cs

示例3: Get

        public async Task<SteamGame> Get(int appId)
        {
            using (var webClient = new WebClient())
            {
                var urlString = "http://store.steampowered.com/api/appdetails?appids={0}";
                var gameUri = new Uri(String.Format(urlString, appId));
                var jsonGameString = await webClient.DownloadStringTaskAsync(gameUri);
                jsonGameString = jsonGameString.Replace("[]", "{}");
                jsonGameString = jsonGameString.Replace("\"package_groups\":{}", "\"package_groups\":[]");

                var jsonSteamGame = JsonConvert.DeserializeObject<JsonSteamGame>(jsonGameString);
                var dlcAppIds = String.Join(",", jsonSteamGame[appId].data.dlc);

                var dlcUri = new Uri(String.Format(urlString, dlcAppIds));
                var jsonDlcString = await webClient.DownloadStringTaskAsync(dlcUri);
                jsonDlcString = jsonDlcString.Replace("[]", "{}");
                jsonDlcString = jsonDlcString.Replace("\"package_groups\":{}", "\"package_groups\":[]");

                var jsonDlcList = JsonConvert.DeserializeObject<JsonSteamGame>(jsonDlcString);
                var gameInformation = jsonSteamGame.First().Value;
                var steamGame = new SteamGame(gameInformation.data);
                foreach (var downloadableContent in jsonDlcList)
                {
                    steamGame.DownloadableContent.Add(new SteamGame(downloadableContent.Value.data));
                }

                return steamGame;
            }
        }
开发者ID:jwendl,项目名称:TypeScript-Angular-Katana-Demos,代码行数:29,代码来源:GameController.cs

示例4: Get

 public static Task<string> Get(string url, string authToken) {
     var client = new WebClient { Encoding = Encoding.UTF8 };
     if (authToken == null)
         return client.DownloadStringTaskAsync(new Uri(url + "&api_key=" + ApiKey));
     client.Headers.Add(AuthHeader(authToken));
     return client.DownloadStringTaskAsync(url);
 }
开发者ID:maximbaz,项目名称:BoxSimpleSync,代码行数:7,代码来源:HttpRequest.cs

示例5: Get

    /// <summary>
    /// Validates oauth 2 access_token against a google provider.
    /// </summary>
    /// <param name="param name="access_token"">
    /// An access token to validate.
    /// </param>
    /// <returns>
    /// Profile info.
    /// </returns>
    public async Task<UserAuthorization> Get(string access_token)
    {
      using(var client = new WebClient())
      {
        client.Headers["Content-Type"] = "application/json";
        client.QueryString["access_token"] = access_token;
        client.QueryString["input_token"] = access_token;

        var info = JsonConvert.DeserializeObject<TokenInfo>(
          await client.DownloadStringTaskAsync(validateUrl));

        client.QueryString.Remove("input_token");

        var profile = JsonConvert.DeserializeObject<Profile>(
          await client.DownloadStringTaskAsync(profileUrl));

        return new UserAuthorization
        {
          Provider = Provider,
          AccessToken = access_token,
          ExpiresAt = new DateTime(1970, 1, 1).AddSeconds(info.data.expires_at),
          ClientId = info.data.app_id,
          Scopes = info.data.scopes ?? new string[0],
          Profile = new UserProfile 
          {
            Provider = Provider,
            UserId = info.data.user_id,
            Name = profile.name,
            Locale = profile.locale,
            Gender = profile.gender,
            Picture = pictureUrl.Replace(":user-id", info.data.user_id)
          }
        };
      }
    }
开发者ID:gerzhan,项目名称:oauth2,代码行数:44,代码来源:FacebookController.cs

示例6: EasySearch

        private async Task<IEnumerable<ISearchResult>> EasySearch(string query, uint maxResults)
        {
            using (var webClient = new WebClient { Proxy = null })
            {
                var result =
                    JsonConvert.DeserializeObject<SearchResult>(
                        await
                            webClient.DownloadStringTaskAsync(
                                $"https://www.googleapis.com/youtube/v3/search?order=relevance&type=video&regionCode={CultureInfo.CurrentCulture.TwoLetterISOLanguageName}&part=snippet&videoDuration=any&maxResults={maxResults}&key={YouTubeApiKey}&q={Uri.EscapeDataString(query)}"));

                var result2 =
                    JsonConvert.DeserializeObject<ContentDetailsResult>(
                        await
                            webClient.DownloadStringTaskAsync(
                                $"https://www.googleapis.com/youtube/v3/videos?id={string.Join(",", result.items.Select(x => x.id.videoId))}&part=contentDetails&key={YouTubeApiKey}"));

                return
                    result.items.Select(
                        x =>
                            new YouTubeSearchResult(x.snippet.title, GetArtist(x.snippet.title, x.snippet.channelTitle),
                                x.snippet.channelTitle, x.id.videoId, XmlConvert.ToTimeSpan(
                                    result2.items.First(y => y.id == x.id.videoId).contentDetails.duration),
                                [email protected]));
            }
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:25,代码来源:YouTubeService.cs

示例7: AccessUrlForNet5Async

        public async void AccessUrlForNet5Async()
        {
            var client = new WebClient();

            GetUrlLength(await client.DownloadStringTaskAsync(new Uri("http://msdn.microsoft.com/zh-tw")));
            GetUrlLength(await client.DownloadStringTaskAsync(new Uri("http://www.microsoft.com/zh-tw")));
            GetUrlLength(await client.DownloadStringTaskAsync(new Uri("http://channel9.msdn.com/")));
            GetUrlLength(await client.DownloadStringTaskAsync(new Uri("http://technet.microsoft.com/zh-TW/")));
        }
开发者ID:chimpinano,项目名称:MVC5Book,代码行数:9,代码来源:MainWindow.xaml.cs

示例8: FetchJson

 private async static Task<string> FetchJson(int comicNumber) {
     string json = "";
     var client = new WebClient();
     if(comicNumber == 0) {
         json = await client.DownloadStringTaskAsync(new Uri(xkcd + info));
     } else {
         json = await client.DownloadStringTaskAsync(new Uri(xkcd + "/" + comicNumber.ToString() + info));
     }
     return json;
 }
开发者ID:jonstodle,项目名称:wpcd,代码行数:10,代码来源:XkcdInterface.cs

示例9: DownloadSamples

        public async void DownloadSamples()
        {
            var wc = new WebClient();
            var samples = await wc.DownloadStringTaskAsync("http://myvar.org/estd/get/all");

            foreach (var item in samples.Split('\r'))
            {
                await wc.DownloadStringTaskAsync(item);
            }
        }
开发者ID:HaKDMoDz,项目名称:eStd,代码行数:10,代码来源:DownloadDialogViewModel.cs

示例10: DownloadStringContent

 public async Task<string> DownloadStringContent(string url)
 {
     using (var client = new WebClient())
     {
         return await client.DownloadStringTaskAsync(new Uri(url)).ConfigureAwait(false);
     }
 }
开发者ID:nagyistoce,项目名称:Magpie,代码行数:7,代码来源:DefaultRemoteContentDownloader.cs

示例11: GetASync

 public async Task<FullCustomer> GetASync(int id)
 {
     var webClient = new WebClient();
     var customerString = await webClient.DownloadStringTaskAsync(BuildUrl(id));
     var customer = JsonConvert.DeserializeObject<Customer>(customerString);
     var fullCustomer = new FullCustomer(customer);
     var orders = new List<Order>();
     foreach (var orderId in customer.OrderIds)
     {
         var orderString = await webClient.DownloadStringTaskAsync(BuildUrl(id, orderId));
         var order = JsonConvert.DeserializeObject<Order>(orderString);
         orders.Add(order);
     }
     fullCustomer.Orders = orders;
     return fullCustomer;
 }
开发者ID:modulexcite,项目名称:WebPerfTestFx,代码行数:16,代码来源:CustomerController.cs

示例12: ProcessRequest

		public async Task ProcessRequest(string uri, MultilineTextBox output = null)
		{
			if (output != null)
				output.AddLine($"Accessing '{uri}'...");

			try
			{
				WebClient client = new WebClient();
				string response = await client.DownloadStringTaskAsync(uri);
				var parsedResponse = JsonConvert.DeserializeObject<Dictionary<string, string>>(response);
				if (output != null)
				{
					output.AddLine("Status: " + parsedResponse["status"]);
					if (parsedResponse.ContainsKey("response"))
						output.AddLine("Response: " + parsedResponse["response"]);
					else
					{
						output.AddLine("Error: " + parsedResponse["error"]);
						Resolved = true;
						_canceller.Cancel();
					}
				}
				Resolved = true;
			}
			catch (Exception ex)
			{
				if (output != null)
					output.AddLine($"ERROR: Exception thrown during access: {ex.Message}");
				Resolved = true;
				_canceller.Cancel();
			}
		}
开发者ID:Enerdy,项目名称:CTRSystem,代码行数:32,代码来源:OutputWindow.xaml.cs

示例13: GetSoundCloudTrack

 private async Task<SoundCloudWebTrackResult> GetSoundCloudTrack(string url)
 {
     using (var web = new WebClient { Proxy = null })
     {
         try
         {
             var result = JsonConvert.DeserializeObject<ApiResult>(await web.DownloadStringTaskAsync(string.Format("http://api.soundcloud.com/resolve.json?url={0}&client_id={1}", url, SensitiveInformation.SoundCloudKey)));
             return new SoundCloudWebTrackResult
             {
                 Duration = TimeSpan.FromMilliseconds(result.duration),
                 Year = result.release_year != null ? uint.Parse(result.release_year.ToString()) : (uint)DateTime.Parse(result.created_at).Year,
                 Title = result.title,
                 Uploader = result.user.username,
                 Result = result,
                 Views = (uint)result.playback_count,
                 ImageUrl = result.artwork_url,
                 Url = result.permalink_url,
                 Genres = new List<Genre> { PlayableBase.StringToGenre(result.genre) },
                 Description = result.description
             };
         }
         catch (Exception)
         {
             return null;
         }
     }
 }
开发者ID:WELL-E,项目名称:Hurricane,代码行数:27,代码来源:SoundCloudApi.cs

示例14: GetSongs

		public async Task<List<Song>> GetSongs()
		{
			var client = new WebClient ();
			const string smallFile = "http://docs.xamarin.com/xamu-wcf/songs-small.json";
			var data = await client.DownloadStringTaskAsync (smallFile);
			return await Task.Run(() => Newtonsoft.Json.JsonConvert.DeserializeObject<List<Song>>(data));
		}
开发者ID:flolovebit,项目名称:xamarin-evolve-2014,代码行数:7,代码来源:WebService.cs

示例15: button1_Click

        private async void button1_Click(object sender, EventArgs e)
        {
            WebClient wc = new WebClient();
            richTextBox1.Text = await wc.DownloadStringTaskAsync("http://tclhost.com/tv1madj.gif");
            MessageBox.Show("Done");

        }
开发者ID:sweko,项目名称:SEDC4-CSharp,代码行数:7,代码来源:Form1.cs


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