u011251204 2021-09-23 17:02 采纳率: 25%
浏览 181
已结题

c# webBrowser 获取 post 返回的数据

c# 如何 获取post 返回的数据 (部分未显示) post返回的是一个表格 但表格内容没有完全显示

img

  • 写回答

5条回答 默认 最新

  • hyh123a 全栈领域新星创作者 2021-09-24 07:31
    关注

    可能对你有用的两个办法:
    办法一:

    办法二:

    C#版本:

        /// <summary>
        /// Fires before navigation occurs in the given object (on either a window or frameset element).
        /// </summary>
        /// <param name="pDisp">Object that evaluates to the top level or frame WebBrowser object corresponding to the navigation.</param>
        /// <param name="url">String expression that evaluates to the URL to which the browser is navigating.</param>
        /// <param name="Flags">Reserved. Set to zero.</param>
        /// <param name="TargetFrameName">String expression that evaluates to the name of the frame in which the resource will be displayed, or Null if no named frame is targeted for the resource.</param>
        /// <param name="PostData">Data to send to the server if the HTTP POST transaction is being used.</param>
        /// <param name="Headers">Value that specifies the additional HTTP headers to send to the server (HTTP URLs only). The headers can specify such things as the action required of the server, the type of data being passed to the server, or a status code.</param>
        /// <param name="Cancel">Boolean value that the container can set to True to cancel the navigation operation, or to False to allow it to proceed.</param>
        private delegate void BeforeNavigate2(object pDisp, ref dynamic url, ref dynamic Flags, ref dynamic TargetFrameName, ref dynamic PostData, ref dynamic Headers, ref bool Cancel);
    
        private void Form1_Load(object sender, EventArgs e)
        {
            dynamic d = webBrowser1.ActiveXInstance;
    
            d.BeforeNavigate2 += new BeforeNavigate2((object pDisp,
                ref dynamic url,
                ref dynamic Flags,
                ref dynamic TargetFrameName,
                ref dynamic PostData,
                ref dynamic Headers,
                ref bool Cancel) => {
    
                // Do something with PostData
            });
        }
    

    C# WPF 版本
    保留上述内容,但替换:

        dynamic d = webBrowser1.ActiveXInstance;
    

    和:

        using System.Reflection;
        ...
        PropertyInfo prop = typeof(System.Windows.Controls.WebBrowser).GetProperty("ActiveXInstance", BindingFlags.NonPublic | BindingFlags.Instance);
        MethodInfo getter = prop.GetGetMethod(true);
        dynamic d = getter.Invoke(webBrowser1, null);
    

    或者下面的方法:

    NET WebBrowser 控件不公开该功能。幸运的是,该控件主要是“旧”控件的包装。这意味着您可以使用类似以下内容(在向您的项目添加对 SHDocVw 的引用之后)订阅您知道和喜爱的 BeforeNavigate2 事件(?):

    Dim ie = DirectCast(WebBrowser1.ActiveXInstance, SHDocVw.InternetExplorer)
    AddHandler ie.BeforeNavigate2, AddressOf WebBrowser_BeforeNavigate2
    

    ... 并对该事件中的 PostData 执行任何您想要的操作:

    Private Sub WebBrowser_BeforeNavigate2(ByVal pDisp As Object, ByRef URL As Object, _
           ByRef Flags As Object, ByRef TargetFrameName As Object, _
           ByRef PostData As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
        Dim PostDataText = System.Text.Encoding.ASCII.GetString(PostData)
    End Sub
    
    评论

报告相同问题?

问题事件

  • 系统已结题 10月1日
  • 赞助了问题酬金 9月23日
  • 创建了问题 9月23日

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题