IWebBrowserApp.Navigate()如何发送POST数据 [英] IWebBrowserApp.Navigate() How to send Post Data
问题描述
我将非常高兴,如果有人可以告诉我通过 SHDocVw.IWebBrowserApp
。
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.
这页是我们应该走的是: http://example.com/check.php
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.
修改
我和我的C#应用程序使用本机的Internet Explorer 7或更高版本,适用于Windows操作系统的尝试,发送一个HTTP请求到特定的URL,使用POST方法的用户名传递和一个用户在服务器端的网页,将处理HTTP响应的密码。
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.
通过 IWebBrowserApp
和导航
方法我能够打开Internet Explorer的一个新窗口/实例,并将其发送到指定的页面(本地或网络),如果还指定发送POST数据和自定义页眉。
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.
但主要问题的,我不知道该怎么我的数据写入到一个POST请求由浏览器来进行。
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.
我将不胜感激帮助。
推荐答案
我发现如何订购IE打开一个网页,发送一些POST数据。
-
添加一个名为COM引用的 Microsoft Internet Explorer中控件的该项目。
然后创建后的字符串
与现场和它的价值分开通过&安培;
,然后将其转换字符串
到字节数组
。
Then create the post string
with the field and its value separated by &
, and then convert that string
into a byte array
.
而在刚刚结束只好请求IE导航到网址
,和也发送POST数据转换成字节数组
,然后添加相同的标题,它的附加当我们提交表单。
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.
这里所说:
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);
注意:
要试试,如果这个工程。不要忘记,你的服务器端页面必须的写/回声的命名邮政领域:用户名和密码。
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代码示例:的
<?php
echo $_POST['username'];
echo " ";
echo $_POST['password'];
?>
的 ASP代码示例:的
<%
response.write(Request.Form("username"))
response.write(" " & Request.Form("password"))
%>
的和页面会显示这样的事情:的
法比奥123
这篇关于IWebBrowserApp.Navigate()如何发送POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!