如何在 C# 中打开带有帖子信息的 IE? [英] How to open IE with post info in C#?
问题描述
我正在开发一个窗口形式的小程序.在这个表单上,我想放一个链接,当用户点击这个链接时,一个单独的 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.
我在网上搜索,有人建议使用Microsoft web browser control",然而,这需要在我的表单中添加这个控件,并在表单中显示资源管理器,但我想单独打开一个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?
推荐答案
在表单上放置一个 Web 浏览器.它的默认名称应该是webBrowser1"——如果你愿意,你可以更改它.将可见"属性设置为假".双击表单标题栏在代码中自动生成加载事件.
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"), "");
}
您可以在其中传递您想要的任何字节数组... Encoding.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屋!