How to make Http Post request using CefSharp - wpf

I have a WPF application where I use CefSharp Browser control to render web pages. I need to be able to perform an HttpPost and open the uri. I looked through CefSharp documentation and haven't found any concrete examples to achieve this functionality but I'm sure this may be a feature that is part of the CefSharp component. Any pointers to how to achieve this would be quite helpful.
Thanks

Are you getting a Url back from your Http Post or some HtmlContent ?
The HttpPost either way has nothing to do with the Web Browser Control.
You can make an Http Post outside of the control, which in turn would return you the html content, and you would use CefSharp to display the content returned using the LoadHtml function, or if you are getting a Url back from your post, then you just need to set the Url of your webbrowser wpf control to the Url returned by your Http Post.

Related

WPF WebBrowser : get Navigation error

I have a WPF application with a WebBrowser control inside.
When I navigate to a website, I would like to know if the page is online or not. I the page is not accessible, I would like to navigate to a local html error page...
How can I do it ?
The first solution I found is to do a WebRequest before navigating, but it require a additional website call... I would like to find an other solution.
I wanted to get the HTTP Status code of the page in the "navigated" event of the WebBrowser, but I found here that it's not possible qith a WebBrowser control because the WebResponse is always null...
Is there an other solution?
This seems a common question, I added a solution here using the .Net NavigationService. Alternatives are also discussed.

Showing the result of a WebClient-postback in an Browser Window from Silverlight 4

I want to show the result of a WebClient-Postback in an new Browser-Popup-Window. As the "Navigate" and "Popup" methods of HtmlPage only support Get-requests, I issued an POST-request to an REST-Service via WebClient. But now I want to show the result (e.g. application/ms-excel or application/pdf) in an new Browser-Window.
Therefore, can I open an new BrowserWindow and set its contents as well as some corresponding http-headers with on-board means of Silverlight 4? Or even better, is an easier way to trigger the browser to do the POST-request to the service?
Best Regards
I tried going this route but the WebBrowser control is not opened to the developer. What I did as a temporary workaround was to open my webpage http://www.xyz.com/default.aspx inside the WebControl and let the page drive the rest.
Mike Taulty had an example for somthing like this, how you can use javascript to communicate back to the silverlight app through InvokeScript:
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-html-hosting-in-the-webbrowser-control.aspx
I hope it helps!

C Sharp DEvelopment of Windows Forms Application

I'm developing a Windows Application in C sharp.using a Web Browser control to Login to the Https Site and Download the List of files. I'm able to login in to the Site and I'm able to Navigate to the Page where files are listed to be downloaded. When I try Downloading the file using the file URL and trying to Navigate using Web Browser Control a Pop - Up appears asking whether to Open or Save or cancel. How to handle this Pop up and I'm stuck here.
Any Answers are appreciated.
Thanks,
Vinay.
If all you are trying to do is download a file, you might be better off using webRequest.Create("Url") instead of the WebBrowser control. There are ways of handling authentication depending on the method the website uses.
It's best not to use the WebBrowser to download files (unless initiated by the user, who can click the save button). Instead, you can use a WebRequest to download the files from your application.
Since you said you have to log in to the website, I'm going to assume that it uses the popular method of using cookies (as opposed to HTTP Basic Auth). To get the cookies from the WebBrowser, you can use the Cookie property of the WebBrowser's Document property.

How to get the response headers while the user navigates from page to page?

I have a WPF webbrowser control which navigates the user to a registration site. After the user registers, a collection of headers are sent back alongwith the "finished registration" page.
I have tried the Navigated event, and tried accessing WebResponse property in the event arguments but it's always null.
Is there any other way to access the headers sent?
After quite a lot of reading, I figured out that WPF web browser actually wraps around the WinForm web browser which inturn wraps around a COM dll (which is even used by Internet Explorer).
Now this COM dll provides a lot of interfaces which are not exposed by any of the wrapper controls. So those who need more control need to implement these interfaces.
I found a browser which implements a lot of these interfaces and neatly provides a lot functionality. Used it and it's working fine. http://www.codeproject.com/KB/miscctrl/csEXWB.aspx
It talks about implemnting a PassthroughAPP package to get the response headers.
I dont think you can access headers like that, best thing to do is, either use Hidden Fields of the form or you can pass on your cookie ASP.NET_SessionID from your finished page to your WPF app, and inside WPF app you can make custom request to your url with same ASP.NET_SessionID cookie where you will continue same session and you will be able to query responses you desire throught WebResponse.

Cross-site images in Silverlight

Is it possible to load in an image from another domain using JavaScript, and then pass the image to a Silverlight control on my page?
The only workaround I'm familiar with for this, since it's a security issue, is to set up a web service on a server you have control over, request the image from this web service from your Silverlight application, then have the service grab the image from the other server and return it to the client.
Loading cross-domain images should not be an issue in Silverlight, at least if you are using the normal Image control. I just tested this with a really simple application containing only an Image control with the Source property set to an image from google images.
Are you loading your images in some funky way with the WebClient? Cross-scheme and cross-zone access is restricted for the Image class, so you would not be able to load an image (on any domain) over SSL if you loaded your XAP over regular HTTP.
The MSDN page on Silverlight URL Access Restrictions gives you a good overview of what you can and cannot do with Image, MediaElement, WebClient, and streaming video.

Resources