質問

before i reference non .net builtin(alternatives)

i would like to know about

The built-in .Net Classes could offer to use :

WebBrowser & WebBrowserBase Classes

what i would like to know is : what are the differences between those two ? .

as msdn noted in Later one - WebBrowserBase -

"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code"

the question began with a simple task : retrieve a file(datasource xml) from a website . sound simple? so you could use any method..., preferably simplest & resource efficient one.

but !

scenario is : that same source (single one to be reliable ) was blocking automatic traffic recently, by using cookies , as i could undersrand WebClient is using the same resources of your main browsers(IE9 in my case) .

....and after a research i have made, using a WebBrowser "Engine" as a file-retriever...

will do the job perfectly .

you could use any (not just Microsoft IE )

about other tests i have made you could visit :

http://seleniumhq.org/docs/03_webdriver.html

+

https://code.google.com/p/selenium/downloads/list

役に立ちましたか?

解決

Your problem

scenario is, that same source (single one to be reliable) was blocking automatic traffic recently by using cookies`

Well, if that is your problem (cookies) Why dont you try this web-client?

public class CookieWebClient : WebClient
{
    private readonly CookieContainer _cookies = new CookieContainer();

    protected override WebRequest GetWebRequest(Uri address)
    {
        WebRequest request = base.GetWebRequest(address);
        HttpWebRequest webRequest = request as HttpWebRequest;
        if (webRequest != null)
        {
            webRequest.CookieContainer = _cookies;
        }
        return request;
    }
}

WebBrowser vs WebBrowserBase

As for the difference between WebBrowser and WebBrowserBase, WebBrowser inherits WebBrowserBase to extend it and make it into a full functional web-browser. Where WebBrowserBase comes in handy is if you would like to customize the WebBrowser beyond what is supported - you can override things and use WebBrowserBase to extend functionality and such. As a rule, unless you absolutely must, you should stick to just using the plain WebBrowser control - and only if you are rendering web pages or would like to use it to hackishly execute javascript.

Comment about extending WebBrowser in general

One of the most useful modifications I've found personally for the webbrowser was exposing the download flags, so you can control whether the webbrowser downloads images etc. A great example of how to do this is here: https://stackoverflow.com/a/7738174/184746

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top