TypeError: g.getResponseHeader is undefined

TypeError: g.getResponseHeader is undefined

我有这个代码:

Connector conn = FrameworkUtil.getConnector(context, ALFRESCO_ENDPOINT_ID);
ConnectorContext c = new ConnectorContext(HttpMethod.POST);
c.setContentType("application/json");

Response res = conn.call("/slingshot/profile/userprofile", c,
                    new ByteArrayInputStream(buf.toString().getBytes()));

这使得 POST 到 link:POST http://localhost:8080/share/service/components/profile/userprofile

但是,我得到了错误:

TypeError: g.getResponseHeader is undefined

...unction(g){var b=g.argument.config;var f=g.getResponseHeader["Content-Type"]||g....

在网上搜索了一下,发现这个问题可以通过添加Content-Type和CORS来解决。

类似于:

 .header("Access-Control-Allow-Headers", "x-requested-with,Content-Type");

如何在我的代码中执行此操作?使用 Connector 或 ConnectorContext 我找不到设置 header...

的方法

或者如果这不是解决这个问题的方法,我该如何解决这个错误?

我认为您可能在这里配置不正确,或者您可能误解了一些事情。如果您正在与 ALFRESCO_ENDPOINT_ID 进行远程连接,那么这通常意味着您正在尝试连接到 Alfresco Repository - 并且根据您所说的您尝试从中进行调用的位置,会出现这是在 Share 应用程序中 Java 支持的 WebScript 运行 - 这是否正确?

如果是这样,应该请求的 URL 实际上是:

http://localhost:8080/alfresco/service/slingshot/profile/userprofile

这相当于调用以下内容:

http://localhost:8080/share/proxy/alfresco/slingshot/profile/userprofile

(第二个 URL 自动代理到 Alfresco enpoint)。

如果您在同一台服务器上同时拥有 Alfresco Repository 和 Share 运行(使用端口 8080 意味着您这样做)那么您不应该遇到 CORS 问题 - 除非您正在尝试从本地主机转到 Alfresco 存储库 运行.

的某个远程位置

Share/Surf 应该为您处理所有这些 - 也许您可以提供更多关于您正在尝试做什么的上下文, 代码在哪里 运行(例如 WebScript、Share 等)以及您尝试连接到哪里?

这可能有助于就如何解决您的主要问题提出最佳建议。