1

I have an application that simulates a post to a web page with post data using the WebBrowser class in a wpf application.

private void openBrowser(CreateDdiRequest postData)
    {
        string serialisedObject = serializeValues(postData);
        string postHeaders = "Content-Type: application/x-www-form-urlencoded";
        _browser.Navigate(new Uri(_url), "_blank", Encoding.UTF8.GetBytes(serialisedObject), postHeaders);
    }

This opens up the IE web browser and pushes the post data to the site. Problem I have now is that I want it to open the default browser not IE.

Is there anyway to achieve this?

James Andrew Smith
  • 1,338
  • 2
  • 18
  • 39

2 Answers2

0

As far as I know, the browser that will be launched is not always the default one.

Follow these steps :

1° Despending of your Windows version, you should search "Default Programs" on the start menu, or in the settings for Windows 8. Well, Search for the "Default Programs" panel in your computer :)

2° Enter Default programs, and then tap or click Default Programs.

3° Tap or click Set your default programs.

4° Select your browser from the list of programs. As you can (maybe) see, the browser is not default for every possible actions ("The program has 15 out of 20 defaults")

5° Tap or click Set this program as default, and then tap or click OK.

If it's not working, try to launch your browser by its path :

Process.Start(@"%AppData%..\Local\Google\Chrome\Application\chrome.exe", "http:\www.YourUrl.com");

Of course, it's working for an external URL, maybe not for what you want.

By the way, if you just want to do a POST request, you don't need the webbrowser class.

 using (var client = new HttpClient())
{
    var values = new Dictionary<string, string>
    {
       { "thing1", "hello" },
       { "thing2", "world" }
    };

    var content = new FormUrlEncodedContent(values);

    var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);

    var responseString = await response.Content.ReadAsStringAsync();
}

Sources :

HTTP request with post

http://windows.microsoft.com/en-US/internet-explorer/make-ie-default-browser#ie=ie-11

How to launch a Google Chrome Tab with specific URL using C#

Community
  • 1
  • 1
  • This is not what I need. I can do a post but I need to open up the browser at the same time. Because I am writing a test rig to simulate different displays depending on the the values posted back. – James Andrew Smith Oct 06 '15 at 14:23
0

To launch the default browser, simply call Process.Start() and pass the form values in the URL.

Process.Start(myUrl)
Dax Pandhi
  • 822
  • 4
  • 13