dtziv24262 2014-02-08 19:00
浏览 21
已采纳

远程API探索无法正常工作(Restler Framework)

I have a Restler-powered API (api.example.com) and I have a website for developers (developer.example.com). My aim is to be able to explore the API from the latter site.

But as I add this to the API Explorer options: discoveryUrl:"http://api.example.com/resources.json" it doesn't work (displays "0 : error http://api.example.com/resources.json") even though these facts:

Could you tell me what can be the cause of this issue?

  • 写回答

1条回答 默认 最新

  • douxian6260 2014-02-09 04:15
    关注

    This is because of the browser that is restricting javascript not to load a remote resource without proper permission

    Read more about Cross-origin resource sharing from the Wikipedia

    In order to enable cross domain access, enable crossOriginResourceSharing on your api server as shown in the following example

    use Luracast\Restler\Restler;
    use Luracast\Restler\Defaults;
    
    require_once "../../../vendor/restler.php";
    
    Defaults::$crossOriginResourceSharing = true;
    
    $r = new Restler();
    $r->addAPIClass('MinMax');
    $r->addAPIClass('MinMaxFix');
    $r->addAPIClass('Type');
    $r->addAPIClass('Resources');
    $r->handle();
    

    Above example is live in http://restler3.luracast.com/tests/param/resources.json you may want to try that from your remote explorer

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失