【发布时间】:2017-12-08 14:21:43
【问题描述】:
我正在尝试使用 anuglarjs http GET 请求从我的 Rest API 控制器获取数据。但是,我需要发送的参数包括“。”导致 URL 失败的符号。我试图对其进行编码,但它不起作用。这是我所做的:
function getApplication($http) {
this.getData = function(application,name) {
return $http({
method : 'GET',
url : http://localhost:8080/app/rest/+ 'app/' + encodeURIComponent(name)
}).then(function successCallback(response) {
return response.data;
}, function errorCallback(response) {
console.log(response.statusText);
});
}
}
名称参数是app.01.com
我得到的网址结果是:
GET http://localhost:8080/app/rest/app/app.01.com 406 (Not Acceptable)
有人知道如何对 url 进行编码,以便我可以从 Rest Controller 获取数据吗? 谢谢
【问题讨论】:
-
将名称作为对象传入请求正文。 {方法:'GET',网址:localhost:8080/app/rest/+'app/',数据:名称}
-
在服务端听起来像是一个糟糕的实现。您可以尝试手动将
.替换为%2E。如果这样可行,则该服务的解析规则过于严格。
标签: angularjs rest angularjs-http