在CEF中注册自定义``backend://`方案不起作用 [英] Registering Custom ``backend://` scheme is not working in CEF

查看:240
本文介绍了在CEF中注册自定义``backend://`方案不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 CEF应用程序

我为方案backend://注册了一个自定义方案处理程序.就像在调用每个进程渲染过程和浏览器过程) AddCustomScheme:

I register a custom scheme handler for the scheme backend://. As done in scheme_handler example I call in every process (Rendere Process and Browser-Process) AddCustomScheme :

void registerCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)
    {
        for(auto& scheme : getCustomSchemes()) // "backend" and "client"
        {
            registrar->AddCustomScheme(scheme,
                                       true /* is standart*/,
                                       false /* is local */,
                                       false /* is display_isolated */,
                                       true /* is secure */,
                                       true /* is cors enabled*/,
                                       false /* is_csp_bypassing*/);
        }
    }

client://方案还安装了处理程序.

The client:// scheme has also a handler installed.

当我不同时使用clientbackend调用AddCustomScheme时. backend://处理程序(和client处理程序一样)有效,但是我没有收到任何后请求数据(我发送了一些二进制数据).

When I dont call AddCustomScheme with both client and backend. The backend:// handler works (as well as the client handler), but I dont receive any post request data (I send some binary data).

当我使用AddCustomScheme时,clientbackend的方案处理程序 不再被触发.

When I use the AddCustomScheme the scheme handlers for client and backend are no more triggered.

我应该如何设置自定义处理程序backend,使其能够接收发布数据请求?我还尝试玩AddCustomHandler中的bool,但没有帮助.

How should I setup the custom handler backend such that it receivs post data requests? I also tried to play around with the bools in AddCustomHandler which did not help.

更新:解决方案 请勿在主机名中使用大写字母!

CefRegisterSchemeHandlerFactory("http", "your-host-name", new ... )

推荐答案

您正在尝试跨域XmlHttpRequest(XHR).您需要配置跨域资源共享(CORS).看看CefAddCrossOriginWhitelistEntry.

You are attempting a cross-origin XmlHttpRequest (XHR). You need to configure Cross-origin resource sharing (CORS). Look at CefAddCrossOriginWhitelistEntry.

WebKit不会将POST数据传递给在非HTTP方案上执行的同步XHR的请求.请参阅XMLHttpRequest::send() in third_party/WebKit/Source/core/XMLHttpRequest.cpp中的AreMethodAndURLValidForSend()检查.

WebKit does not pass POST data to the request for synchronous XHRs executed on non-HTTP schemes. See the AreMethodAndURLValidForSend() checks in XMLHttpRequest::send() in third_party/WebKit/Source/core/XMLHttpRequest.cpp.

bool XMLHttpRequest::AreMethodAndURLValidForSend() {
  return method_ != HTTPNames::GET && method_ != HTTPNames::HEAD &&
         url_.ProtocolIsInHTTPFamily();
}

如果需要使用XHR POST请求,则应使用HTTPHTTPS协议注册自定义处理程序.由于这是故意的WebKit设计功能,因此对于CEF3可能不会更改.

If you need to use XHR POST requests you should register your custom handler using the HTTP or HTTPS protocol. Since this is an intentional WebKit design feature it is likely not changed for CEF3.

这篇关于在CEF中注册自定义``backend://`方案不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆