【问题标题】:http get url modification in angular 1.6http在angular 1.6中获取url修改
【发布时间】:2018-08-22 11:00:15
【问题描述】:

我有一个 Angular 1.6 项目。我的应用基础 url 是https://localhost/abc/#/

我想编写一个 http 服务调用来获取客户端详细信息:https://localhost/api/ccc/v1/client

但是当我将 url 传递给 http.get() 时,它正在点击 https://localhost/abc/api/ccc/v1/client

function getClient() {
    var url = "api/ccc/v1/client";
    return $http.get(url).then((response) => {
      return response;
    });
}

如何从我的 url 中删除“abc”以点击这个 (https://localhost/api/ccc/v1/client) 确切的 api? 有人可以帮帮我吗?

【问题讨论】:

    标签: http url https url-rewriting angular1.6


    【解决方案1】:

    我通过将 ( / ) 添加到 url 找到了解决此问题的方法。

    "var url = "/api/ccc/v1/client";"

    现在,我可以点击这个 (https://localhost/api/ccc/v1/client) 确切的 api 来获取客户详细信息。

    更新代码

    function getClient() {
        var url = "/api/ccc/v1/client";
        return $http.get(url).then((response) => {
          return response;
        });
    }
    

    【讨论】: