Moqui REST API调用失败,错误代码403

时间:2017-06-24 15:26:24

标签: moqui

从我的Angular 2应用程序中我试图从Moqui获取数据,但请求总是失败,错误代码为403。

这是REST API调用实现


        getExample() {
        let url = 'http://localhost:8080/rest/s1/example/examples'
        let headers = new Headers({ 'Authorization': 'Basic 
        am9obi5kb2U6bW9xdWk='});
        headers.append('Accept', 'application/json, text/plain, */*');
        headers.append('Content-Type', 'application/json; charset=UTF-8');
        let options = new RequestOptions({ headers: headers });
        let response = this.http.get(url, options).map(res => res.json());
        return response;
      }

Moqui记录: -

  

禁止访问REST(无authz):对REST路径上的视图/示例/示例不授权用户null

还有一个类似的问题Moqui Rest Nginx,但从答案中我不知道我必须在哪里更改Moqui中的设置。

在客户端控制台上,错误是: -

  

XMLHttpRequest无法加载http://localhost:8080/rest/s1/example/examples。预检的响应具有无效的HTTP状态代码403

但是像YARC这样的休息客户端可以运行: - enter image description here

1 个答案:

答案 0 :(得分:0)

您必须对REST API调用进行身份验证,但配置为不需要身份验证的Service REST API路径除外(例如mantle-usl组件中mantle.rest.xml文件中的/ mantle / my端点)。

您有身份验证,但还有另一个步骤:授权。通常,如果需要authc,则还需要授权。这通常是在种子数据中使用数据库记录完成的,也可以使用默认Moqui运行时(即moqui / moqui-runtime存储库)中包含的System应用程序添加。

在MantleSetupData.xml文件中有一个Service REST API调用的授权设置示例。与屏幕授权的主要区别在于要使用的工件类型是' AT_REST_PATH'。这是GitHub上的文件(靠近文件顶部):

https://github.com/moqui/mantle-usl/blob/master/data/MantleSetupData.xml

关于Moqui中REST请求的大多数事情的最佳文档,目前在' rest.xml'中的注释中。实际处理传入请求的文件(即处理/ rest路径)。你可以在GitHub上看到这个:

https://github.com/moqui/moqui-runtime/blob/master/base-component/webroot/screen/webroot/rest.xml