Example #1
2
 private void SendGETRequest(string url)
 {
     using (WebClient wc = new WebClient())
     {
         wc.DownloadStringAsync(new Uri(url));
     }
 }
Example #2
0
        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);
        }
Example #3
0
 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);
 }
Example #4
0
 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);
 }
    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));
    }
 }/*}}}*/
 //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;
 }/*}}}*/
Example #7
0
File: test.cs Project: mono/gert
	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;
	}
Example #8
0
        // 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/"));
        }
Example #9
0
        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;
        }
 // 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));
 }
    public override System.Collections.IEnumerator Execute(UTContext context)
    {
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayer ||
            EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayerStreamed) {
            Debug.LogWarning("You have currently set the build target to 'Web Player'. This may cause interference with actions that access the internet. If you get an error message about cross domain policy from this action, switch the target to 'PC and Mac Standalone' and try again.");
        }

        var theNexusUrl = nexusUrl.EvaluateIn (context);
        if (string.IsNullOrEmpty (theNexusUrl)) {
            throw new UTFailBuildException ("You need to specify the nexus URL", this);
        }

        var theRepoId = repositoryId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theRepoId)) {
            throw new UTFailBuildException ("You need to specify the repository id.", this);
        }

        var theUserName = userName.EvaluateIn (context);
        var thePassword = password.EvaluateIn (context);

        var theGroupId = groupId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theGroupId)) {
            throw new UTFailBuildException ("You need to specify the group id.", this);
        }

        var theArtifactId = artifactId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theArtifactId)) {
            throw new UTFailBuildException ("You need to specify the artifact id.", this);
        }

        var theVersion = version.EvaluateIn (context);
        if (string.IsNullOrEmpty (theVersion)) {
            throw new UTFailBuildException ("You need to specify the version.", this);
        }

        var thePackaging = packaging.EvaluateIn (context);
        if (string.IsNullOrEmpty (thePackaging)) {
            throw new UTFailBuildException ("You need to specify the packaging.", this);
        }

        var theExtension = extension.EvaluateIn (context);
        var theClassifier = classifier.EvaluateIn (context);

        var theInputFileName = inputFileName.EvaluateIn (context);
        if (string.IsNullOrEmpty (theInputFileName)) {
            throw new UTFailBuildException ("You need to specify the input file name.", this);
        }

        if (Directory.Exists (theInputFileName)) {
            throw new UTFailBuildException ("The specified input file " + theInputFileName + " is a directory.", this);
        }

        if (!File.Exists (theInputFileName)) {
            throw new UTFailBuildException ("The specified input file " + theInputFileName + " does not exist.", this);
        }

        WWWForm form = new WWWForm ();
        form.AddField ("r", theRepoId);
        form.AddField ("g", theGroupId);
        form.AddField ("a", theArtifactId);
        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);
                    }
                }
            }
        }
    }
        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;
        }
Example #13
0
        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);
        }
Example #14
0
    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 ));
    }
    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"));
    }
 //async topPage url parsing:
 private void BeginParseTopicPageURL(string url)
 {
     WebClient wc = new WebClient();
     wc.DownloadStringCompleted +=new DownloadStringCompletedEventHandler(wc_topic_DownloadStringCompleted);
     wc.DownloadStringAsync(new Uri(url));
 }
Example #17
0
 public static async Task ConcurrentOperations_Throw()
 {
     await LoopbackServer.CreateServerAsync((server, url) =>
     {
         var wc = new WebClient();
         Task ignored = wc.DownloadDataTaskAsync(url); // won't complete
         Assert.Throws<NotSupportedException>(() => { wc.DownloadData(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadDataAsync(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadDataTaskAsync(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadString(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadStringAsync(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadStringTaskAsync(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadFile(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadFileAsync(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadFileTaskAsync(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadData(url, new byte[42]); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadDataAsync(url, new byte[42]); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadDataTaskAsync(url, new byte[42]); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadString(url, "42"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadStringAsync(url, "42"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadStringTaskAsync(url, "42"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadFile(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadFileAsync(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadFileTaskAsync(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadValues(url, new NameValueCollection()); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadValuesAsync(url, new NameValueCollection()); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadValuesTaskAsync(url, new NameValueCollection()); });
         return Task.CompletedTask;
     });
 }
Example #18
0
        public static void DownloadString_InvalidArguments_ThrowExceptions()
        {
            var wc = new WebClient();

            Assert.Throws<ArgumentNullException>("address", () => { wc.DownloadString((string)null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.DownloadString((Uri)null); });

            Assert.Throws<ArgumentNullException>("address", () => { wc.DownloadStringAsync((Uri)null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.DownloadStringAsync((Uri)null, null); });

            Assert.Throws<ArgumentNullException>("address", () => { wc.DownloadStringTaskAsync((string)null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.DownloadStringTaskAsync((Uri)null); });
        }
Example #19
-1
    private void CreateBodyPart(System.Uri meshUrl, System.Uri jpgUrl)
    {
        //download jpg and save into a jpg file.
        Debug.Log ("trying to load " + meshUrl.AbsoluteUri);
        WebClient webClient = new WebClient ();

        webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownCompleted);
        webClient.DownloadStringAsync (meshUrl);

        jpgUrlPath = jpgUrl;
    }