Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

internet explorer - How to open IE with post info in C#?

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.

Original, i used System.Diagnostics.Process.start(). However, I can not post data through this kind of call.

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Call the Navigate method, which has this signature:

void Navigate(string urlString, string targetFrameName, byte[] postData, string additionalHeaders);

Like this:

private void Form1_Load(object sender, EventArgs e)
{
    webBrowser1.Navigate("http://www.google.com/", "_blank", Encoding.Default.GetBytes("THIS IS SOME POST DATA"), "");
}

You can pass any array of bytes you want in there... Encoding.Default.GetBytes() is just a fast way to pass a string through.

The trick is to use "_blank" for the target frame.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...