IWebBrowserApp.Navigate() 如何发送Post数据

发布于 2024-09-11 12:14:34 字数 649 浏览 4 评论 0原文

如果有人可以向我展示如何使用导航方法发送 POST 数据的好示例(可通过 SHDocVw.IWebBrowserApp 获取),我将非常高兴。

考虑例如。

我们应该去的页面是:http://example.com/check.php

并且应该发送两个输入字段的值:用户名和密码。

编辑

我正在尝试使用我的 C# 应用程序使用 Windows 操作系统上可用的本机 Internet Explorer 版本 7 或更高版本,将 HTTP 请求发送到特定 URL,使用 POST 方法传递用户名和将用户密码发送到处理 HTTP 响应的服务器端页面。

使用 IWebBrowserAppNavigate 方法,我可以打开 Internet Explorer 的新窗口/实例并将其发送到特定页面(本地或网络中),并且如果指定,还发送 POST 数据和自定义标头。

但主要问题是我不知道如何将数据写入浏览器携带的 POST 请求中。

我将不胜感激的帮助。

I would be very glad if someone could show me a good example of how to send POST data with the Navigate Method, available through SHDocVw.IWebBrowserApp.

Considering for example.

That the page were we should go is: http://example.com/check.php

And should send the values of two input fields named: username and password.

EDIT

I'm attempting with my C# App to use the native Internet Explorer version 7 or higher, available on Windows OS, to send a HTTP Request to a specific URL, passing using the POST method the username and password of an user to a server side page that would handle the HTTP Response.

With IWebBrowserApp and the Navigate method I'm able to open a new window/instance of Internet Explorer and send it to a specific page (local or in the web), and if specified also send POST data and custom headers.

But the main problem its that i don't know how to write my data into a POST request to be carried by the browser.

I would appreciate help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2024-09-18 12:14:34

我已经找到了如何命令 IE 打开网页并发送一些 POST 数据。

  • 将名为 Microsoft Internet Explorer Controls 的 COM 引用添加到项目中。 p>

  • 然后创建 post 字符串,其中字段及其值以 & 分隔,然后将该 字符串 转换为 字节数组

  • 最后只需请求 IE 导航到 url,并将 Post Data 转换为 字节数组 发送,然后添加相同的 Header它是在我们提交表单时添加的。

这里是:

using SHDocVw; // Don't forget

InternetExplorer IEControl = new InternetExplorer();
IWebBrowserApp IE = (IWebBrowserApp)IEControl;
IE.Visible = true;

// Convert the string into a byte array
ASCIIEncoding Encode = new ASCIIEncoding();
byte[] post = Encode.GetBytes("username=fabio&password=123");

// The destination url
string url = "http://example.com/check.php";

// The same Header that its sent when you submit a form.
string PostHeaders = "Content-Type: application/x-www-form-urlencoded";

IE.Navigate(url, null, null, post, PostHeaders);

注意:

尝试一下这是否有效。不要忘记您的服务器端页面必须写入/回显名为:用户名和密码的帖子字段。

PHP 代码示例:

<?php
echo $_POST['username'];
echo " ";
echo $_POST['password'];
?>

ASP 代码示例:

<%
response.write(Request.Form("username"))
response.write(" " & Request.Form("password"))
%>

页面将显示如下内容:

法比奥123

I've found how to order IE to open a webpage and send some POST data.

  • Add a COM Reference named Microsoft Internet Explorer Controls to the project.

  • Then create the post string with the field and its value separated by &, and then convert that string into a byte array.

  • And in the end just had to request IE to Navigate to the url, and also send the Post Data converted into a byte array, and then add the same Header that its added when we submit a form.

Here goes:

using SHDocVw; // Don't forget

InternetExplorer IEControl = new InternetExplorer();
IWebBrowserApp IE = (IWebBrowserApp)IEControl;
IE.Visible = true;

// Convert the string into a byte array
ASCIIEncoding Encode = new ASCIIEncoding();
byte[] post = Encode.GetBytes("username=fabio&password=123");

// The destination url
string url = "http://example.com/check.php";

// The same Header that its sent when you submit a form.
string PostHeaders = "Content-Type: application/x-www-form-urlencoded";

IE.Navigate(url, null, null, post, PostHeaders);

NOTE:

To try if this works. Don't forget that your server side page would have to write/echo the Post fields named: username and password.

PHP Code Example:

<?php
echo $_POST['username'];
echo " ";
echo $_POST['password'];
?>

ASP Code Example:

<%
response.write(Request.Form("username"))
response.write(" " & Request.Form("password"))
%>

And the page would display something like this:

fabio 123

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文