【发布时间】:2016-05-30 05:34:09
【问题描述】:
我想知道是否有一种动态的方式来获取基本 url,以便在 http 请求中使用?
有没有办法动态获取 http://192.123.24.2:8080?
public getAllTickets() {
this._http.get('http://192.123.24.2:8080/services/', {
method: 'GET',
headers: new Headers([
'Accept', 'application/json',
'Content-Type', 'application/json'
])
})
所以,我的请求看起来像:
public getAvailableVersions() {
this._http.get('../services', {
method: 'GET',
headers: new Headers([
'Accept', 'application/json',
'Content-Type', 'application/json'
])
})
我正在寻找一种不必对 REST 调用的 URL 进行硬编码的方法。还是唯一的选择是在 URL 中使用全局变量?
谢谢!
【问题讨论】:
-
这是您要找的东西吗:
window.location.host? -
谢谢!!这样就解决了。
-
但是,我认为在我的下一个解决方案中,我将设置一个全局变量。当我实现它时,我会在这篇文章中添加评论:)
标签: rest http url service angular