cefsharp / Questions-and-Support

Use this repository to ask CefSharp specific questions
BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

C# GET API request #61

Closed goldenone closed 3 years ago

goldenone commented 3 years ago

Hello, thanks for your great work!

Is it possible to make an GET request with cefsharp and display the returned website with ChromiumWebBrowse in a c# WinForrm?

I have made some tries, but it doesn't work.. Thankful for every help! `

        CefSettings settings = new CefSettings();
        // Initialize cef with the provided settings
        Cef.Initialize(settings);
        // Create a browser component
        chromeBrowser = new ChromiumWebBrowser();

        IFrame frame = chromeBrowser.GetMainFrame();
        IRequest request = frame.CreateRequest();

        request.Url = "https://myUrl/?auth=KIS";
        request.Method = "GET";

        //Headers
        NameValueCollection headers = new NameValueCollection();
        headers.Add("username", "support");
        headers.Add("accesstoken", "mytoken");
        request.Headers = headers;

        //Request
        frame.LoadRequest(request);

        // Add it to the form and fill it to the form window.
        this.Controls.Add(chromeBrowser);
        chromeBrowser.Dock = DockStyle.Fill;`
amaitland commented 3 years ago

LoadRequest can only be used if a renderer process already exists. In newer versions initially loading about:blank no longer creates a renderer process. You can load a Data Uri initially then call this method. https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs WARNING: This method will fail with "bad IPC message" reason INVALID_INITIATOR_ORIGIN (213) unless you first navigate to the request origin using some other mechanism (LoadURL, link click, etc).

As per http://cefsharp.github.io/api/85.3.x/html/M_CefSharp_IFrame_LoadRequest.htm You need to successfully load a url before you call LoadRequest, you can load a data uri initially rather than an external website.

See also https://github.com/cefsharp/CefSharp/wiki/General-Usage#load-url-with-postdata

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.