1

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

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

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;
    });
  };
})();
1
  • 1
    What does your controller look like? Commented Feb 22, 2016 at 16:40

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.