如何用C#中的帖子信息打开IE? [英] How to open IE with post info in C#?
问题描述
我正在开发一个以windows形式出现的小程序。在此表单上,我想放置一个链接,当用户点击该链接时,将打开一个单独的IE浏览器,其中包含发布数据。
I am developing a small program which as a windows form. On this form, I want to put a link, and when user click the link, a seperate IE browser will be open with post data.
原创,我使用 System.Diagnostics.Process.start()
。但是,我无法通过这种电话发布数据。
Original, i used System.Diagnostics.Process.start()
. However, I can not post data through this kind of call.
我在网上搜索,有人建议使用微软网络浏览器控制,但是,这需要在我的表单中添加此控件,并在表单中显示资源管理器,但我想要一个单独的IE打开。
And I searched the web, some guy suggested to use "Microsoft web browser control", however, this need to add this control in my form,and display the explorer in the form, but I want a seperate IE opened.
我在VB中看到有一个方法为 CreateObject(InternetExplorer.Application)
,但我找不到如何在C#中使用它。
And I saw in VB there is a method as CreateObject("InternetExplorer.Application")
, but I can not find how to use it in C#.
所以,你有什么建议吗?
So, do you have any suggestions on how to implement?
推荐答案
在你的表格上放一个网页浏览器。它的默认名称应为webBrowser1 - 如果您愿意,可以更改它。将Visible属性设置为False。双击表单标题栏以在代码中自动生成加载事件。
Drop a web browser on your form. It should have a default name of "webBrowser1" - you can change that if you like. Set the "Visible" property to "False". Double-click the form title bar to auto generate a load event in the code.
调用Navigate方法,该方法具有以下签名:
Call the Navigate method, which has this signature:
void Navigate(string urlString, string targetFrameName, byte[] postData, string additionalHeaders);
喜欢这样:
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.google.com/", "_blank", Encoding.Default.GetBytes("THIS IS SOME POST DATA"), "");
}
你可以传递你想要的任何字节数组......编码。 Default.GetBytes()只是传递字符串的快捷方式。
You can pass any array of bytes you want in there... Encoding.Default.GetBytes() is just a fast way to pass a string through.
诀窍是使用_blank作为目标框架。
The trick is to use "_blank" for the target frame.
这篇关于如何用C#中的帖子信息打开IE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!