TOP

Winform用Post方式打开IE
2017-10-11 17:20:09 】 浏览:9758
Tags:Winform Post 方式 打开

1.主要实现Code

 1  void OpenNewIe(string url, string postData)///url是要post的网址,postData是要传入的参数
 2         {
 3             if (ie != null)///避免重复打开ie对象没有释放,抛出异常
 4             {
 5                 try
 6                 {
 7                     ie.Quit();
 8                 }
 9                 catch
10                 {
11                     ie = null;
12                 }
13             }
14             ie = new InternetExplorer();
15             object vPost, vHeaders, vFlags, vTargetFrame;
16             vPost = Encoding.GetEncoding("GB2312").GetBytes(postData);///注意编码方式是GB2312,还是ASCII
17             vFlags = null;
18             vTargetFrame = null;
19             vHeaders = "Content-Type: application/x-www-form-urlencoded" + Convert.ToChar(10) + Convert.ToChar(13);
20             ie.Visible = true;
21             ie.Navigate(url, ref vFlags, ref vTargetFrame, ref vPost, ref vHeaders);
23         }

2.参数传递

1  StringBuilder postData = new StringBuilder();
2             postData.AppendFormat("uid={0}", HelpEncrypt.Encode(uid.ToString(), key));
3             postData.AppendFormat("&serial_number={0}", HelpEncrypt.Encode(serial_number, key));

 3.调用方法

1  if (checkBoxNo.Checked)
2             {
3                 OpenNewIe(Parameter.Payaddress, postData.ToString());               
4             }

4.附加:用WebBrowser组件Post打开IE

1 private void TransferWebForm_Load(object sender, EventArgs e)
2         {
3             string vHeaders = "Content-Type: application/x-www-form-urlencoded" + Convert.ToChar(10) + Convert.ToChar(13);
4             byte[] vPost = Encoding.GetEncoding("GB2312").GetBytes(_postData);
5             this.webBrowser1.Navigate(navigateUrl, null, vPost, vHeaders);
6         }

 


Winform用Post方式打开IE https://www.cppentry.com/bencandy.php?fid=102&id=141841

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇查看电脑硬件信息,主板、内存等 下一篇非常全面的讲解Hosts文件