I'm trying to pass JSON from script to C++ using a custom "client" scheme handler and XMLHttpRequest in the script code. I've set disable-web-security to allow cross-site XmlHttpRequests.
The request is arriving at ClientSchemeHandler::ProcessRequest and the URL is passed but request->GetPostData(); returns NULL.
Scheme registration (most of the handler / factory code was copied from scheme_test.cc)
- Code: Select all
int APIENTRY _tWinMain(
CefRegisterSchemeHandlerFactory("client", "app", new ClientSchemeHandlerFactory());
void CEFMyApp::OnRegisterCustomSchemes(
registrar->AddCustomScheme("client", true, false, false);
Event handler
- Code: Select all
bool ClientSchemeHandler::ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
{
CEF_REQUIRE_IO_THREAD();
bool handled = false;
std::string url = request->GetURL();
int count = 0;
CefRefPtr<CefPostData> post = request->GetPostData();
if (post != NULL)
count = post->GetElementCount();
LogTRACE("ClientSchemeHandler::ProcessRequest (%s) - POST addr = %x, count = %d", url.c_str(), post, count);
Log 12:00:56 - ClientSchemeHandler::ProcessRequest (client://app/json.htm?key=free&s2=bunny&bId=1234) - POST addr = 0, count = 0
Script code on a simple test page (I tried passing as both JSON and as form-encoded):
- Code: Select all
<html>
<script>
function do_post()
{
//alert('posting');
var zbytes = "j={x{y{z}}}"; //"{x{y{z}}}";
var zhttp = new XMLHttpRequest();
var zurl = "client://app/json.htm?key=free&s2=bunny&bId=1234";
zhttp.open("POST", zurl, true);
zhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // ('Content-Type', 'application/json');
zhttp.send(zbytes);
alert('posted');
}
</script>
<body onLoad="do_post();">
<p>Hey nonny nonny!
</p>
</body>
</html>
Any idea why the POST body is not being included in the request object?