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


C# WebClient.SetPostData方法代码示例

本文整理汇总了C#中System.Net.WebClient.SetPostData方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.SetPostData方法的具体用法?C# WebClient.SetPostData怎么用?C# WebClient.SetPostData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了WebClient.SetPostData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: bLoad_Click

        private void bLoad_Click(object sender, EventArgs e)
        {
            // Load URL contents and show a wait cursor in the meantime
            Cursor = Cursors.WaitCursor;

            try
            {
                using (WebClient client = new WebClient(this.UserAgent))
                {
                    string expandedUrl = null;
                    string postData = null;

                    // Note: The Text property might modify the text value
                    using (ProgressDialog dialog = new ProgressDialog("Loading URL", "Please wait while the content is being downloaded..."))
                    {
                        dialog.OnDoWork = delegate()
                        {
                            expandedUrl = CurrentVariable.ExpandedUrl;
                            if (dialog.Cancelled) return false;
                            client.SetPostData(CurrentVariable);
                            postData = client.PostData;
                            CurrentVariable.TempContent = client.DownloadString(new Uri(expandedUrl));
                            return true;
                        };
                        dialog.OnCancel = delegate()
                        {
                            dialog.Cancel();
                        };
                        dialog.ShowDialog(this);
                        
                        // Did an error occur?
                        if (!dialog.Cancelled && dialog.Error != null)
                        {
                            LogDialog.Log("Failed loading URL", dialog.Error);

                            // Check whether or not the URL is valid and show an error message if necessary
                            if (dialog.Error is ArgumentNullException || string.IsNullOrEmpty(expandedUrl))
                            {
                                MessageBox.Show(this, "The URL you entered is empty and cannot be loaded.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else if (dialog.Error is UriFormatException)
                            {
                                MessageBox.Show(this, "The specified URL '" + expandedUrl + "' is not valid.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else
                            {
                                MessageBox.Show(this, "The contents of the URL can not be loaded: " + dialog.Error.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }

                    rtfContent.Text = CurrentVariable.TempContent;
                    // For Regex: Go to match after thread finish
                    this.gotoMatch = true;
                    UpdateRegexMatches();
                    // For Start/End: Go to match now
                    RefreshRtfFormatting();

                    this.GoToMatch();

                    // Show page preview if desired
                    if (cmnuBrowser.Checked)
                    {
                        PreviewDialog.ShowPreview(this, expandedUrl, postData);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "An error occured when loading the URL: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
开发者ID:RyanGrange,项目名称:Ketarin,代码行数:76,代码来源:EditVariablesDialog.cs


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