本文整理汇总了C#中System.Net.WebClient.DownloadStringAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.WebClient.DownloadStringAsync方法的具体用法?C# System.Net.WebClient.DownloadStringAsync怎么用?C# System.Net.WebClient.DownloadStringAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了System.Net.WebClient.DownloadStringAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FontsManager
public FontsManager()
{
m_client = new System.Net.WebClient();
m_client.DownloadStringCompleted += m_client_DownloadStringCompleted;
m_client.Proxy = null;
m_client.DownloadStringAsync(new Uri("https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyDs93IH2UgudQK5IyNSdvKnm1N8TIYzlcM"));
}
示例2: StartLuYiXia
/// <summary>
/// 开始撸一下
/// </summary>
public static void StartLuYiXia()
{
using (
var ludown = new System.Net.WebClient
{
Encoding = System.Text.Encoding.UTF8,
Proxy = PublicStatic.MyProxy
})
{
ludown.DownloadStringAsync(new System.Uri(LuYiXiaApi));
ludown.DownloadStringCompleted += Ludown_DownloadStringCompleted;
}
}
示例3: StartSearchPage
/// <summary>
/// 下载影视资料页的数据
/// </summary>
/// <param name="eachPage"></param>
public static void StartSearchPage(string eachPage)
{
if (string.IsNullOrEmpty(eachPage)) return;
using (
var urldown = new System.Net.WebClient
{
Encoding = System.Text.Encoding.UTF8,
Proxy = PublicStatic.MyProxy
})
{
urldown.DownloadStringAsync(new System.Uri(eachPage));
urldown.DownloadStringCompleted += Urldown_DownloadStringCompleted;
}
}
示例4: ModifyListItem
public static void ModifyListItem(string oldname, string oldurl, string newname, string newurl)
{
if (oldname.IsNullOrEmptyOrSpace()) return;
if (oldurl.IsNullOrEmptyOrSpace()) return;
if (newname.IsNullOrEmptyOrSpace()) return;
if (newurl.IsNullOrEmptyOrSpace()) return;
var wc = new System.Net.WebClient();
wc.Headers.Add(@"KCPlayer", @"KCPlayer.WatchTV.Admin.Modify");
wc.Proxy = null;
wc.DownloadStringAsync(
new System.Uri(string.Format("{0}?Modify={1}|{2}|{3}|{4}", ListWebPath, oldname, oldurl, newname,
newurl)));
wc.DownloadStringCompleted += wc_mod_DownloadStringCompleted;
}
示例5: Search
public Search()
{
var temppath = @"http://www.yyets.com/php/search/index?type=resource&keyword=" + PublicStatic.SearchWord;
if (string.IsNullOrEmpty(temppath)) return;
// 开始下载地址层
using (
var datadown = new System.Net.WebClient
{
Encoding = System.Text.Encoding.UTF8,
Proxy = PublicStatic.MyProxy
})
{
datadown.DownloadStringAsync(new System.Uri(temppath));
datadown.DownloadStringCompleted += Datadown_DownloadStringCompleted;
}
}
示例6: GetData
protected virtual void GetData(string fileName)
{
#if WPF
Uri uri = new Uri(string.Format(this.WpfPath, fileName), UriKind.RelativeOrAbsolute);
System.Windows.Resources.StreamResourceInfo streamInfo = System.Windows.Application.GetResourceStream(uri);
using (StreamReader fileReader = new StreamReader(streamInfo.Stream))
{
GetDataCompleted(this.ParseData(fileReader));
}
#else
Uri dataURI = new Uri(Telerik.Windows.Examples.Timeline.URIHelper.CurrentApplicationURL, string.Format(this.SilverlightPath, fileName));
System.Net.WebClient dataRetriever = new System.Net.WebClient();
dataRetriever.DownloadStringCompleted += DownloadStringCompleted;
dataRetriever.DownloadStringAsync(dataURI);
#endif
}
示例7: AwaitWebClient
private static async Task<String> AwaitWebClient(Uri uri)
{
// Класс System.Net.WebClient поддерживает событийную модель
// асинхронного программирования
var wc = new System.Net.WebClient();
// Создание объекта TaskCompletionSource и его внутреннего объекта Task
var tcs = new TaskCompletionSource<String>();
// При завершении загрузки строки объект WebClient инициирует
// событие DownloadStringCompleted, завершающее TaskCompletionSource
wc.DownloadStringCompleted += (s, e) =>
{
if (e.Cancelled) tcs.SetCanceled();
else if (e.Error != null) tcs.SetException(e.Error);
else tcs.SetResult(e.Result);
};
// Начало асинхронной операции
wc.DownloadStringAsync(uri);
// Теперь мы можем взять объект Task из TaskCompletionSource
// и обработать результат обычным способом.
String result = await tcs.Task;
// Обработка строки результата (если нужно)...
return result;
}
示例8: GetThisUrl
/// <summary>
/// 开始下载链接地址页面数据
/// </summary>
/// <param name="isCopy"></param>
/// <param name="iType"></param>
public static void GetThisUrl(bool isCopy, LiuXingType iType)
{
if (iType == null) return;
if (iType.Data == null) return;
if (string.IsNullOrEmpty(iType.Data.Url)) return;
using (
var urldown = new System.Net.WebClient
{
Encoding = iType.Encoding,
Proxy = iType.Proxy
})
{
var iClass = new LiuXingType
{
Type = iType.Type,
Encoding = iType.Encoding,
Proxy = iType.Proxy,
Data = iType.Data,
IsCopy = isCopy
};
urldown.DownloadStringAsync(new System.Uri(iType.Data.Url), iClass);
urldown.DownloadStringCompleted += urldown_DownloadStringCompleted;
}
}
示例9: StartList
/// <summary>
/// 1.开始列表获取
/// </summary>
/// <param name="path"></param>
/// <param name="iType"></param>
public static void StartList(string path, LiuXingType iType)
{
if (string.IsNullOrEmpty(path)) return;
// 解析数据
using
(
var datadown = new System.Net.WebClient
{
Encoding = iType.Encoding,
Proxy = iType.Proxy
}
)
{
datadown.Headers.Add(System.Net.HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1581.2 Safari/537.36");
if (iType.Sign.Contains("M1905List"))
{
datadown.Headers.Add("order", "listorder");
datadown.Headers.Add("videotype", "3");
datadown.Headers.Add(System.Net.HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
datadown.UploadStringAsync(new System.Uri(path), "POST", "page=1&pagesize=10&order=listorder&videotype=3", iType);
datadown.UploadStringCompleted += Datadown_UploadStringCompleted;
}
else
{
if (iType.Sign.Contains("M1905Second"))
{
datadown.Headers.Add("filmid", iType.Sign.Split(',')[1]);
datadown.Headers.Add(System.Net.HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
datadown.UploadStringAsync(new System.Uri(UrlCodeHelper.GetListHttpPath(0, 0, iType).Replace("filmlist", "filmdetail")), "POST", "filmid=" + iType.Sign.Split(',')[1], iType);
datadown.UploadStringCompleted += Datadown_UploadStringCompleted;
}
else
{
if (iType.Type == LiuXingEnum.ZhangYuSearchItem)
{
datadown.Headers.Add("Cookie", "Hm_lvt_69521636d966ad606a32d89b1d70ee73=1376875963,1376889226; Hm_lpvt_69521636d966ad606a32d89b1d70ee73=1376889233; ce=gY1lvwT");
}
if (iType.Type == LiuXingEnum.DyfmHotApi)
{
datadown.Headers.Add("Cookie", "last_visit=" + System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 24) + "Hm_lpvt_10701d9b4e040e37e58bee7e1ec1d252=1376902145");
}
datadown.DownloadStringAsync(new System.Uri(path), iType);
datadown.DownloadStringCompleted += Datadown_DownloadStringCompleted;
}
}
}
}
示例10: Button_Click_1
private void Button_Click_1(object sender, RoutedEventArgs e)
{
System.Net.WebClient wc = new System.Net.WebClient();
try
{
wc.DownloadStringAsync(new Uri(urlTextBox.Text));
}
catch
{
ReportManage.ErrReport(null, urlTextBox.Text + "のダウンロードに失敗しました");
}
wc.DownloadStringCompleted += (o, e1) => {
if (e1.Error != null)
{
ReportManage.ErrReport(null, urlTextBox.Text + "のダウンロードに失敗しました。 " + e1.Error.Message);
}
else
{
textEditor.Text = e1.Result;
}
};
}
示例11: Datadown_DownloadStringCompleted
private static void Datadown_DownloadStringCompleted(object sender,
System.Net.DownloadStringCompletedEventArgs e)
{
if (e.Error != null || e.Result.Length <= 0 || e.Cancelled)
{
return;
}
var resultstr = e.Result;
if (string.IsNullOrEmpty(resultstr)) return;
//
// 得到<ul class=\"x-movie-list nav nav-pills\" style=\"padding-top:0;\"> ~ </ul>
var orignlis = resultstr.GetSingle("<ul class=\"x-movie-list nav nav-pills\" style=\"padding-top:0;\">",
"</ul>");
if (string.IsNullOrEmpty(orignlis))
{
return;
}
// 得到 <li> ~ </li>
var orignli = orignlis.GetValue("<li>", "</li>");
if (orignli == null || orignli.Count <= 0) return;
// 得到影片页地址
var urls = new System.Collections.Generic.List<string>();
for (var i = 0; i < orignli.Count; i++)
{
var celllistr = orignli[i];
if (string.IsNullOrEmpty(celllistr)) continue;
// 电影名称
var tempname = celllistr.GetSingle("<a target=\"_blank\" href=\"",
"</a> <span class=\"muted\">");
if (!string.IsNullOrEmpty(tempname))
{
if (tempname.Contains(">"))
{
if (tempname.Length > 0)
{
var spitename = tempname.Split('>');
// 电影网址
var urltemp = "http://dianying.fm" + spitename[0].Replace("\"", "");
if (!string.IsNullOrEmpty(urltemp))
{
urls.Add(urltemp);
}
}
}
}
}
if (urls.Count > 0)
{
foreach (var url in urls)
{
if (!string.IsNullOrEmpty(url))
{
using (
var urldown = new System.Net.WebClient
{
Encoding = System.Text.Encoding.UTF8,
Proxy = PublicStatic.MyProxy
})
{
urldown.DownloadStringAsync(new System.Uri(url));
urldown.DownloadStringCompleted += SearchUrl.Urldown_DownloadDataCompleted;
}
}
}
}
}
示例12: processUpdateString
private void processUpdateString()
{
if (String.IsNullOrEmpty(updateString))
{
MessageBox.Show("File was corrupt!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
return;
}
String[] lines = updateString.Split(new String[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
onlineVersion = lines[0];
changeLogLink = lines[1];
downloadLink = lines[2];
if (String.IsNullOrEmpty(onlineVersion) || String.IsNullOrEmpty(changeLogLink) || String.IsNullOrEmpty(downloadLink))
{
MessageBox.Show("File was corrupt!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
return;
}
label1.Text = label1.Text.Replace("{{yourversion}}", thisVersion);
label1.Text = label1.Text.Replace("{{newversion}}", onlineVersion);
System.Version thisVersionZ = new Version(thisVersion);
System.Version onlineVersionZ = new Version(onlineVersion);
if (thisVersionZ < onlineVersionZ)
{
System.Net.WebClient wc2 = new System.Net.WebClient();
wc2.DownloadStringCompleted += new System.Net.DownloadStringCompletedEventHandler(wc2_DownloadStringCompleted);
wc2.DownloadStringAsync(new Uri(changeLogLink));
}
else
{
MessageBox.Show("You have the latest version installed", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
this.Dispose();
}
}
示例13: DeleteListItem
public static void DeleteListItem(string itemname, string itemurl)
{
if (itemname.IsNullOrEmptyOrSpace()) return;
if (itemurl.IsNullOrEmptyOrSpace()) return;
var wc = new System.Net.WebClient();
wc.Headers.Add(@"KCPlayer", @"KCPlayer.WatchTV.Admin.Delete");
wc.Proxy = null;
wc.DownloadStringAsync(
new System.Uri(string.Format("{0}?Delete={1}|{2}", ListWebPath, itemname, itemurl)));
wc.DownloadStringCompleted += wc_Del_DownloadStringCompleted;
}
示例14: DayFromGoogleAsync
public static bool DayFromGoogleAsync(string Symbol, BarListDelegate resultHandler, bool appendAmexOnFail)
{
System.Net.WebClient wc = new System.Net.WebClient();
wc.DownloadStringCompleted +=new System.Net.DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
try
{
wc.DownloadStringAsync(new Uri(GOOGURL + Symbol), new BarListDownload(Symbol, resultHandler,appendAmexOnFail));
}
catch (System.Net.WebException) { return false; }
catch (Exception) { return false; }
return true;
}
示例15: GetFlashUrl
private static void GetFlashUrl(string url, VodUrlType vodType)
{
if (!string.IsNullOrEmpty(url))
{
if (!url.StartsWith("http://"))
{
url = "http://" + url;
}
using (var getFlash = new System.Net.WebClient())
{
getFlash.Proxy = null;
getFlash.Encoding = vodType == VodUrlType.Tudou ? System.Text.Encoding.GetEncoding("GBK") : System.Text.Encoding.UTF8;
getFlash.DownloadStringAsync(
new System.Uri(url), vodType);
getFlash.DownloadStringCompleted += getFlash_DownloadStringCompleted;
}
}
}