0

I am new to webbrowser control, I need to download string from server via Rest API in web browser control of my window application.

Is there any replacement of webClientObject.DownloadString() method in webbrowser control.

Rama Krishna
  • 645
  • 10
  • 28
  • Do you mean you just want to get the HTML source of the page you're currently viewing in the WebBrowser? – Equalsk Oct 24 '17 at 09:59
  • No, I want to call a Rest API from my webbrowser and catch the response – Rama Krishna Oct 24 '17 at 10:01
  • That doesn't really make sense, why would you use a `WebBrowser` for that? It's not what it's meant for at all. Why can't you use `WebClient`? – Equalsk Oct 24 '17 at 10:15
  • @RamaKrishna - Why Stick to WebBrowserControl? Why cant you use HttpWebRequest? With WebBrowserControl you can only call GET Apis. To do that just navigate to the GET Api --- like: http://server:port/rest/ApiName. This will do GET call to the Url. – Prateek Shrivastava Oct 24 '17 at 10:16
  • I am using WebBrowser for login user via SSO, after completion of successful login I need to capture user authentication details like sessionID .etc. – Rama Krishna Oct 24 '17 at 10:16
  • @Prateek Shrivastava Yes you are right, but my API is response is string how can I capture that string into variable? – Rama Krishna Oct 24 '17 at 10:20

1 Answers1

1

Try call Navigate method

webBrowser1.Navigate(new Uri(address));

then call WebBrowser.OnNavigated Method.

private void webBrowser1_Navigated(object sender,
    WebBrowserNavigatedEventArgs e)
{
    // get webBrowser1.DocumentText Property or webBrowser1. DocumentStream 

You can try WebBrowser.InvokeScript this link to get javascript variable or ịnject javascript to get Rest APi url, or Rest API content

tuan huynh
  • 727
  • 5
  • 13