我正在嘗試使用anuglarjs http GET請求從Rest API控制器獲取數據。但是,我需要發送的參數包括「。」導致網址失敗的符號。我試圖編碼它,但它不起作用。下面是我做的:如何在angularJS中對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
和URL結果我得到的是:
GET http://localhost:8080/app/rest/app/app.01.com 406 (Not Acceptable)
任何人都知道如何編碼的URL,這樣我可以得到的數據從休息控制器? 謝謝
通行證名稱作爲請求主體的對象。方法:'GET', url:http:// localhost:8080/app/rest/+'app /',data:name } – jbrown
聽起來就像服務端的一個不好的實現。您可以嘗試用'%2E'手動替換'.'。如果這有效,那麼服務在解析規則上過於嚴格。 –