如果有人能够通过导航方法向我展示如何使用导航方法发送POST数据的一个很好的例子,我将非常高兴SHDocVw.IWebBrowserApp.
考虑到例如.
该页面应该是:http://example.com/check.php
并且应该发送两个输入字段的值:username和password.
编辑
我正在尝试使用我的C#应用程序使用Windows操作系统上提供的本机Internet Explorer 7或更高版本将HTTP请求发送到特定URL,使用POST方法将用户的用户名和密码传递给服务器端将处理HTTP响应的页面.
使用IWebBrowserApp和Navigate方法我可以打开Internet Explorer的新窗口/实例并将其发送到特定页面(本地或Web),如果指定也发送POST数据和自定义标头.
但主要的问题是,我不知道如何将我的数据写入浏览器携带的POST请求中.
我很感激帮助.
我已经找到了如何命令IE打开网页并发送一些POST数据.
将名为Microsoft Internet Explorer Controls的COM引用添加到项目中.
然后创建post string与字段及其值分隔的&,然后将其string转换为byte array.
并且最后只需要请求IE导航到url,并且还将Post Data转换为a byte array,然后添加它在我们提交表单时添加的相同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);
Run Code Online (Sandbox Code Playgroud)
注意:
试试这是否有效.不要忘记您的服务器端页面必须写/回显名为的用户名和密码的Post字段.
PHP代码示例:
<?php
echo $_POST['username'];
echo " ";
echo $_POST['password'];
?>
Run Code Online (Sandbox Code Playgroud)
ASP代码示例:
<%
response.write(Request.Form("username"))
response.write(" " & Request.Form("password"))
%>
Run Code Online (Sandbox Code Playgroud)
页面将显示如下内容:
法比奥123
| 归档时间: |
|
| 查看次数: |
11443 次 |
| 最近记录: |