本文整理汇总了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"));
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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)
}
};
}
}
示例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®ionCode={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]));
}
}
示例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/")));
}
示例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;
}
示例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);
}
}
示例10: DownloadStringContent
public async Task<string> DownloadStringContent(string url)
{
using (var client = new WebClient())
{
return await client.DownloadStringTaskAsync(new Uri(url)).ConfigureAwait(false);
}
}
示例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;
}
示例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();
}
}
示例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;
}
}
}
示例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));
}
示例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");
}