Reputation: 6909
I am sending a request to a Web API from my javascript code as follows:
http://localhost:49358/api/myClasses/GetMyData/first%20second/third%20fourth%2Ffifth
where
is my controller method to which i am passing two parameters first second
and third fourth/fifth
A whitespace gets escaped automatically by %20
automatically and /
I escape using %2F
The issues is that the url call above returns error 404. Meanwhile if I replace third fourth/fifth
by any valid value not containing forward slash, everything works just fine.
Could anyone point me in the right direction?
My controller code is below:
(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;
});
};
})();
Upvotes: 1
Views: 2857
Reputation: 6909
Turns out it is not a client-side issue, as I encoded the slash. The real issue is that the server cannot handle the slash in the parameter in the url. I have decided to replace the slash with underscore and modify my Web API to replace all the underscores with a forward slash later on. Any other suitable character can be used as well
Upvotes: 1