本文整理汇总了C#中WebClient.DownloadStringAsync方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.DownloadStringAsync方法的具体用法?C# WebClient.DownloadStringAsync怎么用?C# WebClient.DownloadStringAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebClient
的用法示例。
在下文中一共展示了WebClient.DownloadStringAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendGETRequest
private void SendGETRequest(string url)
{
using (WebClient wc = new WebClient())
{
wc.DownloadStringAsync(new Uri(url));
}
}
示例2: go
private void go()
{
progressBar1.Visibility = System.Windows.Visibility.Visible;
progressBar1.IsIndeterminate = true;
WebClient WC = new WebClient();
// System.Text.Encoding.Convert(System.Text.Encoding.UTF8, System.Text.Encoding.GetEncoding("cp949"),query.Text);
// WC.Encoding=System.Text.Encoding.GetEncoding("cp949");
var temp = EUCKR_Unicode_Library.EUCKR_Unicode_Converter.GetEucKRString(
query.Text
);
var sb=new StringBuilder();
foreach (byte i in temp)
{
sb.Append("%");
sb.Append(i.ToString("X"));
}
var temp2 = System.Text.Encoding.UTF8.GetString(
temp, 0, temp.Length
);
var temp3 = System.Net.HttpUtility.UrlEncode(
sb.ToString()
);
WC.DownloadStringAsync(new Uri("http://www.acornpub.co.kr/API/search.php?page=1&pageSize=25&keyword=" +
sb.ToString()
));
WC.DownloadStringCompleted += new System.Net.DownloadStringCompletedEventHandler(Completed);
}
示例3: Quit
public void Quit()
{
var runTime = DateTime.Now.Subtract(DataCommonUtils.AppStartTime).Seconds;
var clientByQuit = new WebClient();
string content = string.Format("Action=0&A=2&B=1&C={0}&C1={1}&D={2}&E={3}&F={4}&G={5}&H={6}&I=0&J={7}&K={8}", C, C1, D, EpgUtils.ClientVersion, D, Y2, Y2, runTime, Y1);
string uri = CreateUri(content);
clientByQuit.DownloadStringAsync(uri);
}
示例4: StartUp
public void StartUp()
{
var clientByStartUp = new WebClient();
string content = string.Format("Action=0&A=1&B=1&C={0}&C1={1}&D={2}&E={3}&F={4}&G={5}&H={6}&I={7}",
C, C1, D, EpgUtils.ClientVersion, D, Y2, Y2, Y1);
string uri = CreateUri(content);
clientByStartUp.DownloadStringAsync(uri);
}
示例5: LoadJsonString
public void LoadJsonString(string url)
{
Debug.Log ("trying to load " + url);
WebClient webClient = new WebClient ();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownCompleted);
webClient.DownloadStringAsync (new System.Uri(url));
}
示例6: DownloadStringAsTask
}/*}}}*/
//03sub EAP2TPl Event-based Async Pattern
static Task<string> DownloadStringAsTask(Uri address) {/*{{{*/
TaskCompletionSource<string> tcs =
new TaskCompletionSource<string>();
WebClient client = new WebClient();
client.DownloadStringCompleted += (sender, args) => {
if (args.Error != null) tcs.SetException(args.Error);
else if (args.Cancelled) tcs.SetCanceled();
else tcs.SetResult(args.Result);
};
client.DownloadStringAsync(address);
return tcs.Task;
}/*}}}*/
示例7: Main
static int Main ()
{
WebClient objClient = new WebClient ();
objClient.DownloadStringCompleted += objClient_DownloadStringCompleted;
objClient.DownloadStringAsync (new Uri ("http://www.google.com"));
while (!_complete) {
}
if (_result == null)
return 1;
if (_result.IndexOf ("<html>") == -1)
return 2;
return 0;
}
示例8: DownloadHomepage
// it's actually impossible to really show this old-style in a Windows Store app
// the non-async APIs just don't exist :-)
public void DownloadHomepage()
{
var webClient = new WebClient(); // not in Windows Store APIs
webClient.DownloadStringCompleted += (sender, e) =>
{
if (e.Cancelled || e.Error != null)
{
// do something with error
}
string contents = e.Result;
int length = contents.Length;
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
ResultTextView.Text += "Downloaded the html and found out the length.\n\n";
});
webClient.DownloadDataCompleted += (sender1, e1) =>
{
if (e1.Cancelled || e1.Error != null)
{
// do something with error
}
SaveBytesToFile(e1.Result, "team.jpg");
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
ResultTextView.Text += "Downloaded the image.\n";
var img = ApplicationData.Current.LocalFolder.GetFileAsync("team.jpg");
var i = new BitmapImage(new Uri(img.Path, UriKind.Absolute));
DownloadedImageView.Source = i;
});
if (downloaded != null)
downloaded(length);
};
webClient.DownloadDataAsync(new Uri("http://xamarin.com/images/about/team.jpg"));
};
webClient.DownloadStringAsync(new Uri("http://xamarin.com/"));
}
示例9: Reload
public void Reload()
{
if (IsLoading)
return;
var wc = new WebClient();
wc.DownloadStringCompleted += (sender, args) =>
{
_wc = null;
if (args.Cancelled || args.Error != null)
return;
var contentType = wc.ResponseHeaders[HttpResponseHeader.ContentType]
.MaskNull().Split(new[] { ';' }, 2)[0];
var jsonContentTypes = new[] {
"application/json",
"application/x-javascript",
"text/javascript",
};
if (!jsonContentTypes.Any(s => s.Equals(contentType, StringComparison.OrdinalIgnoreCase)))
return;
using (var sc = new ScriptControl { Language = "JavaScript" })
{
var data = sc.Eval("(" + args.Result + ")"); // TODO: JSON sanitization
ClosedStatuses = new ReadOnlyCollection<string>(
new OleDispatchDriver(data)
.Get<IEnumerable>("closed")
.Cast<object>()
.Select(o => new OleDispatchDriver(o).Get<string>("name"))
.ToArray());
}
IsLoaded = true;
OnLoaded();
};
wc.DownloadStringAsync(IssueOptionsFeedUrl());
_wc = wc;
}
示例10: BeginParseImageURL
// asych url string downloading functions
private void BeginParseImageURL(string url)
{
WebClient wc = new WebClient();
wc.Encoding = System.Text.Encoding.GetEncoding(936);
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri(url));
}
示例11: Execute
//.........这里部分代码省略.........
form.AddField ("v", theVersion);
if (!string.IsNullOrEmpty (thePackaging)) {
form.AddField ("p", thePackaging);
}
if (!string.IsNullOrEmpty (theClassifier)) {
form.AddField ("c", theClassifier);
}
if (!string.IsNullOrEmpty (theExtension)) {
form.AddField ("e", theExtension);
}
var bytes = File.ReadAllBytes (theInputFileName);
form.AddBinaryData ("file", bytes, new FileInfo (theInputFileName).Name);
var hash = UTils.ComputeHash (bytes);
if (UTPreferences.DebugMode) {
Debug.Log ("SHA1-Hash of file to upload: " + hash);
}
string authString = theUserName + ":" + thePassword;
var authBytes = System.Text.UTF8Encoding.UTF8.GetBytes (authString);
var headers = new Hashtable ();
foreach (var key in form.headers.Keys) {
headers.Add (key, form.headers [key]);
}
headers.Add ("Authorization", "Basic " + System.Convert.ToBase64String (authBytes));
var url = UTils.BuildUrl (theNexusUrl, "/service/local/artifact/maven/content");
using (var www = new WWW (url, form.data, headers)) {
do {
yield return "";
} while(!www.isDone && !context.CancelRequested);
if (UTPreferences.DebugMode) {
Debug.Log ("Server Response: " + www.text);
}
}
if (!context.CancelRequested) {
using (var wc = new WebClient()) {
if (!string.IsNullOrEmpty (theUserName)) {
Debug.Log("Setting credentials" );
wc.Credentials = new NetworkCredential (theUserName, thePassword);
}
Uri uri = new Uri (UTils.BuildUrl (theNexusUrl, "/service/local/artifact/maven/resolve?") +
"g=" + Uri.EscapeUriString (theGroupId) +
"&a=" + Uri.EscapeUriString (theArtifactId) +
"&v=" + Uri.EscapeUriString (theVersion) +
"&r=" + Uri.EscapeUriString (theRepoId) +
"&p=" + Uri.EscapeUriString (thePackaging) +
(!string.IsNullOrEmpty (theClassifier) ? "&c=" + Uri.EscapeUriString (theClassifier) : "") +
(!string.IsNullOrEmpty (theExtension) ? "&e=" + Uri.EscapeUriString (theExtension) : ""));
var downloadFinished = false;
var error = false;
string result = null;
wc.DownloadStringCompleted += delegate( object sender, DownloadStringCompletedEventArgs e) {
downloadFinished = true;
error = e.Error != null;
if (error) {
Debug.LogError ("An error occured while downloading artifact information. " + e.Error.Message, this);
} else {
result = (string)e.Result;
}
};
wc.DownloadStringAsync (uri);
do {
yield return "";
if (context.CancelRequested) {
wc.CancelAsync ();
}
} while(!downloadFinished);
if (!context.CancelRequested) {
if (!error) {
if (UTPreferences.DebugMode) {
Debug.Log ("Server Response: " + result);
}
if (result.Contains ("<sha1>" + hash + "</sha1>")) {
Debug.Log ("Successfully uploaded artifact " + theInputFileName + ".", this);
} else {
throw new UTFailBuildException ("Upload failed. Checksums do not match.", this);
}
} else {
throw new UTFailBuildException ("Artifact verification failed", this);
}
}
}
}
}
示例12: DownloadIssues
public Action DownloadIssues(string project, int start, bool includeClosedIssues,
Func<IEnumerable<Issue>, bool> onData,
Action<DownloadProgressChangedEventArgs> onProgress,
Action<bool, Exception> onCompleted)
{
Debug.Assert(project != null);
Debug.Assert(onData != null);
var client = new WebClient();
Action<int> pager = next => client.DownloadStringAsync(
new GoogleCodeProject(project).IssuesCsvUrl(next, includeClosedIssues));
client.DownloadStringCompleted += (sender, args) =>
{
if (args.Cancelled || args.Error != null)
{
if (onCompleted != null)
onCompleted(args.Cancelled, args.Error);
return;
}
var issues = IssueTableParser.Parse(new StringReader(args.Result)).ToArray();
var more = onData(issues);
if (more)
{
start += issues.Length;
pager(start);
}
else
{
if (onCompleted != null)
onCompleted(false, null);
}
};
if (onProgress != null)
client.DownloadProgressChanged += (sender, args) => onProgress(args);
pager(start);
return client.CancelAsync;
}
示例13: Play
public void Play(DACPlayInfo playInfo, int playType)
{
var clientByPlayEnd = new WebClient();
var builder = new StringBuilder(100);
builder.AppendFormat("Action=0&A={0}&B=1&C={1}&C1={2}&VVID={3}&D={4}", playType, C, C1, playInfo.vvid, D);
if (PersonalFactory.Instance.Logined)
{
var d1 = PersonalFactory.Instance.DataInfos[0].UserStateInfo.VIP == 0 ? "1" : "2";
builder.AppendFormat("&D1={0}&D2={1}", d1, PersonalFactory.Instance.DataInfos[0].UserStateInfo.UserName);
}
else
{
builder.Append("&D1=0");
}
builder.AppendFormat("&D3={0}", WAYGetFactory.WayGetInfo.UserType);
builder.AppendFormat("&E={0}", EpgUtils.ClientVersion);
builder.AppendFormat("&F={0}&F1=1", playInfo.type);
builder.AppendFormat("&G={0}", playInfo.vid);
builder.AppendFormat("&H={0}", playInfo.title);
builder.AppendFormat("&I={0}", playInfo.playTime);
builder.AppendFormat("&J={0}", playInfo.mp4Name);
builder.AppendFormat("&FT={0}", playInfo.ft);
builder.AppendFormat("&FN={0}", playInfo.fn);
builder.AppendFormat("&FM={0}", playInfo.allTime);
builder.AppendFormat("&K={0}", playInfo.programSource);
builder.AppendFormat("&L={0}", playInfo.prepareTime);
builder.AppendFormat("&M={0}", playInfo.bufferTime);
builder.AppendFormat("&N={0}", playInfo.allBufferCount);
builder.AppendFormat("&O={0}", playInfo.dragCount);
builder.AppendFormat("&P={0}", playInfo.dragBufferTime);
builder.AppendFormat("&Q={0}", playInfo.playBufferCount);
builder.AppendFormat("&R={0}", playInfo.connType);
builder.AppendFormat("&S={0}", playInfo.isPlaySucceeded);
builder.AppendFormat("&T={0}", 1);
builder.AppendFormat("&U={0}", string.Empty);
builder.AppendFormat("&V={0}", playInfo.averageDownSpeed);
builder.AppendFormat("&W={0}", playInfo.stopReason);
builder.AppendFormat("&Y1={0}", Y1);
builder.AppendFormat("&Y2={0}", Y2);
builder.AppendFormat("&Y3={0}", Y2);
var uri = CreateUri(builder.ToString());
clientByPlayEnd.DownloadStringAsync(uri);
}
示例14: _request
private void _request(string[] request, AsyncResponse callback = null, string query = "")
{
WebClient client = new WebClient ();
string url = origin + String.Join("/", request) + "?" + query;
debug( url );
client.Headers.Add("V","1.0");
client.Headers.Add("User-Agent","Unity3D");
client.DownloadStringCompleted += (s,e) => {
if( callback != null ) {
Hashtable response = new Hashtable();
if(e.Cancelled != false || e.Error != null) {
response.Add("error", true);
}
else {
response.Add("message", (ArrayList)JSON.JsonDecode((string)e.Result));
}
callback( response );
}
client.Dispose();
};
client.DownloadStringAsync(new Uri( url ));
}
示例15: RefreshData
private void RefreshData()
{
richTextBox1.Text += dot + "Checking for updates...\n";
WebClient client = new WebClient();
client.DownloadStringCompleted += RefreshCompleted;
client.DownloadStringAsync(new Uri("http://sds.webs.pm/update.json"));
}