2016-02-22 19 views
0

我從我的javascript代碼發送到Web API的請求時,削減在JavaScript如下:逃離今後通過URL參數

http://localhost:49358/api/myClasses/GetMyData/first%20second/third%20fourth%2Ffifth

其中

http://localhost:49358/api/myClasses/GetMyData/

是我的控制器的方法,我想過去兩個參數first secondthird fourth/fifth

一個空格被自動%20/自動轉義我逃使用%2F

的問題是,URL調用上述返回錯誤404同時如果我用任何不包含正斜槓的有效值代替third fourth/fifth,那麼一切正常。

任何人都可以指向正確的方向嗎?

我的控制器代碼如下:

(function() { 
    angular.module("myApp").controller("MyController", ["$scope", "$state", "$http", MyFunction]); 

    function MyFunction($scope, $state, $http) { 
    $scope.MyClass1=[]; 
    $http.get('http://localhost:49358/api/myClasses/GetMyData/' + $scope.$parent.param1 + '/' + encodeURIComponent($scope.$parent.param2)) 
     .then(function (result) { 
     $scope.MyClass1 = result.data; 
    }); 
    }; 
})(); 
+1

你的控制器是什麼樣的? –

回答

0

原來它不是一個客戶端的問題,因爲我編碼的斜線。真正的問題是服務器無法在url中的參數中處理斜槓。我決定用下劃線替換斜線,並修改我的Web API以便稍後用正斜槓替換所有下劃線。任何其他合適的字符都可以使用