本文整理汇总了C#中System.Net.WebClient.DownloadStringTask方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.DownloadStringTask方法的具体用法?C# WebClient.DownloadStringTask怎么用?C# WebClient.DownloadStringTask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了WebClient.DownloadStringTask方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitContent
private async void InitContent()
{
try{
var client = new WebClient();
string content="";
content = await client.DownloadStringTask(new Uri("http://www.9gag.com/random"));
string replaceWith = "";
content = content.Replace("\r\n", replaceWith).Replace("\n", replaceWith).Replace("\r", replaceWith).Replace(" ", replaceWith);
var s1 = content.Substring(content.IndexOf("img-wrap"));
s1 = s1.Remove(0, 19);
var s2 = s1.Split('\"');
ImageField.Source = new BitmapImage(new Uri("http:" + s2[0]));
//titleBox.Text = jsonObject["title"].GetString();
//string imgSource = "http:" + jsonObject["gag"].GetString();
//var uri = new Uri(imgSource, UriKind.Absolute);
//ImageField.Source = new BitmapImage(uri);
}
catch (Exception)
{
InitContent();
}
}
示例2: Test
async Test()
{
// download the google home page
WebClient client = new WebClient();
var google = client.DownloadStringTask("http://www.google.com");
yield return google;
// find and download the first link on the google home page
Regex regex = new Regex("href=\"(?<href>http://.*?)\"");
var match = regex.Match(google.Result);
var firstHref = match.Groups["href"].Value;
var firstHrefTask = client.DownloadStringTask(firstHref);
yield return firstHrefTask;
yield return new UIThreadTask(this);
button.Text = firstHrefTask.Result.Substring(0, 10);
}
示例3: LoadData
public async void LoadData()
{
IsLoading = true;
var client = new WebClient();
try
{
string webcontent = await client.DownloadStringTask(new Uri("http://meteo.search.ch/" + Plz));
string uriString = "http://meteo.search.ch/images/chart/" + GetImageUrl(webcontent);
var source = new BitmapImage(new Uri(uriString));
ImageSource = source;
ExtractDescription(webcontent);
}
catch (Exception e) { }
finally { IsLoading = false; }
}
示例4: DoExecute
/// <summary>
/// 실제 작업을 정의합니다.
/// </summary>
/// <param name="context">Quartz <see cref="JobExecutionContext"/></param>
/// <param name="token">작업중 중단를 할 수 있도록 하는 Token</param>
public override void DoExecute(JobExecutionContext context, CancellationToken token) {
var jobName = context.JobDetail.FullName;
if(IsDebugEnabled)
log.Debug(@"Job[{0}]을 시작합니다...", jobName);
var targetUri = context.GetJobData("TargetUri") as Uri;
using(var client = new WebClient()) {
var task = client.DownloadStringTask(targetUri ?? new Uri(@"http://debop.egloos.com"));
Task.WaitAll(new[] { task }, token);
if(IsDebugEnabled) {
log.Debug("다운로드를 받았습니다.");
log.Debug(task.Result);
}
}
if(IsDebugEnabled)
log.Debug(@"Job[{0}]을 완료했습니다.", jobName);
}
示例5: DispatcherTest
async DispatcherTest()
{
// download the google home page
WebClient client = new WebClient();
var google = client.DownloadStringTask("http://www.google.com");
yield return google;
// find and download the first link on the google home page
Regex regex = new Regex("href=\"(?<href>http://.*?)\"");
var match = regex.Match(google.Result);
var firstHref = match.Groups["href"].Value;
var firstHrefTask = TaskHelper.Create(client.DownloadString, firstHref);
yield return firstHrefTask;
// let's yield back onto the Dispatcher to get onto the UI thread
yield return this.Dispatcher();
textBox1.Text = firstHrefTask.Result;
}
示例6: Ping
public void Ping() {
using(var client = new WebClient()) {
client.DownloadStringTask(GetScriptUrl()).Result.Should().Not.Be.Null();
}
}