Url post data in CefGlue

Having problems with building or using the CefGlue .NET/Mono binding? Ask your questions here.

Moderator: fddima

Url post data in CefGlue

Postby escribano » Thu Nov 22, 2012 12:17 pm

Hi! I want to find an alternative to webbrowser control in .NET. This control has a "Navigate" method that provides post data functionality. How can I replicate this "Navigate" method with CefGlue?

Best Regards!
escribano
Newbie
 
Posts: 3
Joined: Thu Nov 22, 2012 11:59 am

Re: Url post data in CefGlue

Postby fddima » Fri Nov 23, 2012 3:32 am

You needed create request with CefRequest.Create() and setup request, as you needed including post data.
Then you interested in CefFrame.LoadRequest(CefRequest request) method. (You can obtain frame via CefBrowser.GetMainFrame()).
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Url post data in CefGlue

Postby escribano » Mon Nov 26, 2012 12:47 pm

Thank you very much. Web is shown correctly but I get an error when a pdf integrated in browser is loading. If I delete this code works perfectly and I assume that this code causes the issue.

public void NavigateTo(string url)
{
if (_browser != null)
{

//Data has some data

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Byte[] bytes = Encoding.UTF8.GetBytes(data);

CefRequest peticion = CefRequest.Create();
CefPostData post_data = CefPostData.Create();
CefPostDataElement element = CefPostDataElement.Create();

element.SetToBytes(bytes);
post_data.Add(element);

System.Collections.Specialized.NameValueCollection headers = new NameValueCollection();
headers.Add("Content-Type", "application/x-www-form-urlencoded");

peticion.Set(url, "POST", post_data, headers);

Address = url;
_browser.CefBrowser.StopLoad();
//_browser.CefBrowser.GetMainFrame().LoadUrl(url);
_browser.CefBrowser.GetMainFrame().LoadRequest(peticion);


}
}


Could you help me?

Error: Attempted to read or write protected memory. This is often an indication that other memory has been corrupted
escribano
Newbie
 
Posts: 3
Joined: Thu Nov 22, 2012 11:59 am

Re: Url post data in CefGlue

Postby fddima » Mon Nov 26, 2012 1:57 pm

escribano wrote:Thank you very much. Web is shown correctly but I get an error when a pdf integrated in browser is loading. If I delete this code works perfectly and I assume that this code causes the issue.

Quick look at you sample gives working for me. I'm doesn't understand how it is related to pdf? Can you explain more precisely?
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Url post data in CefGlue

Postby fddima » Mon Nov 26, 2012 2:01 pm

escribano wrote:Thank you very much. Web is shown correctly but I get an error when a pdf integrated in browser is loading. If I delete this code works perfectly and I assume that this code causes the issue.
I'm also post request like your to web server which returns pdf, and it is works... So, sorry, don't have idea.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Url post data in CefGlue

Postby escribano » Tue Nov 27, 2012 3:47 am

For example, when I try to open http://www.choapa.org/karamazov.pdf with cef_binary_3.1327.908_windows_xilium\Release\cefclient.exe I get this error in console.log:

Message: Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101
Source: http://tests/xmlhttprequest
Line: 9
-----------------------

Message: Invalid 'X-Frame-Options' header encountered when loading 'http://www.google.es/url?sa=t&rct=j&q=karamazov%20pdf&source=web&cd=1&ved=0CC4QFjAA&url=http%3A%2F%2Fwww.choapa.org%2Fkaramazov.pdf&ei=NnK0UJPcPIHD0QWE4IEg&usg=AFQjCNGvudII-vw9L1p4e_BvIz6Xr9YX3g': 'ALLOWALL' is not a recognized directive. The header will be ignored.

Source: http://www.google.es/url?sa=t&rct=j&q=k ... Iz6Xr9YX3g


Line: 0

Any idea?

Thanks in advance!
escribano
Newbie
 
Posts: 3
Joined: Thu Nov 22, 2012 11:59 am

Re: Url post data in CefGlue

Postby fddima » Tue Nov 27, 2012 5:10 am

escribano wrote:For example, when I try to open http://www.choapa.org/karamazov.pdf with cef_binary_3.1327.908_windows_xilium\Release\cefclient.exe I get this error in console.log:


I did not have any problems with opening this url.
I have adobe acrobat reader installed, and looked that when i'm opening this url, it is handled by pdf plugin.

My plugin info from cefclient:
Code: Select all
Name: Adobe Acrobat
Description: Adobe PDF Plug-In For Firefox and Netscape 10.1.4
Version: 10.1.4.38
Path: C:\Program Files (x86)\Adobe\Reader 10.0\Reader\Browser\nppdf32.dll
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Url post data in CefGlue

Postby sebarnolds » Fri Feb 08, 2013 5:23 am

Hello.

Thanks for those informations, I easily made POST requests. However, is there any way to do such a request without a reference to the main frame (and LoadRequest) ? As I want to do the request directly after having created the browser, I currently need to load "about:blank" and create my request on the LoadingStateChanged event.

Am I doing right ? Is there another way to do this ?
sebarnolds
Techie
 
Posts: 18
Joined: Fri Nov 09, 2012 10:16 am

Re: Url post data in CefGlue

Postby fddima » Fri Feb 08, 2013 6:11 am

sebarnolds wrote:Hello.

Thanks for those informations, I easily made POST requests. However, is there any way to do such a request without a reference to the main frame (and LoadRequest) ? As I want to do the request directly after having created the browser, I currently need to load "about:blank" and create my request on the LoadingStateChanged event.

Am I doing right ? Is there another way to do this ?


Use about:blank - browser always starts from some url. So your's solution is normal.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Url post data in CefGlue

Postby sebarnolds » Fri Feb 08, 2013 7:12 am

Ok, thanks for the quick answer.
sebarnolds
Techie
 
Posts: 18
Joined: Fri Nov 09, 2012 10:16 am


Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 45 guests