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


C# WebClient.DownloadStringAsync方法代码示例

本文整理汇总了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));
     }
 }
开发者ID:nburns,项目名称:main_trunk,代码行数:7,代码来源:NetworkInterface.cs

示例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);
        }
开发者ID:hoyajigi,项目名称:Acornpub-for-wp7,代码行数:28,代码来源:Search.xaml.cs

示例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);
 }
开发者ID:uvbs,项目名称:MyProjects,代码行数:8,代码来源:DACFactory.cs

示例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);
 }
开发者ID:uvbs,项目名称:MyProjects,代码行数:8,代码来源:DACFactory.cs

示例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));
    }
开发者ID:bosung90,项目名称:MadScientist,代码行数:8,代码来源:CreateSampleMesh.cs

示例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;
 }/*}}}*/
开发者ID:FirstProgramingStudy301-B,项目名称:another,代码行数:14,代码来源:APM2TPL.cs

示例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;
	}
开发者ID:mono,项目名称:gert,代码行数:13,代码来源:test.cs

示例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/"));
        }
开发者ID:ARMoir,项目名称:mobile-samples,代码行数:44,代码来源:MainPage.xaml.cs

示例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;
        }
开发者ID:newmyl,项目名称:gurtle,代码行数:45,代码来源:GoogleCodeProject.cs

示例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));
 }
开发者ID:richie315066406,项目名称:wp7-learning-proj,代码行数:8,代码来源:ImageDownloader.cs

示例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);
                    }
                }
            }
        }
    }
开发者ID:realshyfox,项目名称:PlayMakerCustomActions_U3,代码行数:101,代码来源:UTUploadDependencyAction.cs

示例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;
        }
开发者ID:csware,项目名称:GurtleReloaded,代码行数:45,代码来源:GoogleCodeProject.cs

示例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);
        }
开发者ID:uvbs,项目名称:MyProjects,代码行数:46,代码来源:DACFactory.cs

示例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 ));
    }
开发者ID:AngeloYazar,项目名称:pubnub-unity3d,代码行数:23,代码来源:Pubnub.cs

示例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"));
    }
开发者ID:sakisds,项目名称:Icy-Monitor,代码行数:8,代码来源:CheckForUpdatesDialog.cs


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