zoukankan      html  css  js  c++  java
  • Winform用Post方式打开IE

    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         }
  • 相关阅读:
    268. Missing Number
    217. Contains Duplicate
    189. Rotate Array
    Two Sum II
    122. Best Time to Buy and Sell Stock II
    169. Majority Element
    C# ConfigurationManager不存在问题解决
    C# sqlhelper
    C#基础
    数据库事务日志已满的解决办法
  • 原文地址:https://www.cnblogs.com/yt1219787097/p/4923673.html
Copyright © 2011-2022 走看看