Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm trying to get the data from my Rest API controller using anuglarjs http GET request. However, the params that I need to send include "." symbol which caused the URL failed. I tried to encode it but it does not work. Here is what I did:

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);
      });
    }
  }

The name param is app.01.com

and the URL result I got is:

GET http://localhost:8080/app/rest/app/app.01.com 406 (Not Acceptable)

anyone know how to encode the url so I can get the data from Rest Controller? Thanks

share|improve this question
    
Pass name in as an object on the request body. { method : 'GET', url : localhost:8080/app/rest/+ 'app/', data: name } – jbrown yesterday
    
Sounds like a bad implementation on the service side. You could try manually replacing . with %2E. If that works, the service is being too strict in its parsing rules. – Mike McCaughan yesterday

Have you try to put the url datas into double quotes ? url : "http://localhost:8080/app/rest/+ 'app/' + encodeURIComponent(name)"

share|improve this answer

It is not possible that "." is an unreserved character and that "URIs that differ in the replacement of an unreserved character with its corresponding percent-encoded US-ASCII octet are equivalent". Therefore, /%2E is the same as /. , and that will get normalized away.

then you can use localhost:8080/app/rest/app/app%2E01.com as your urls

share|improve this answer

Use btoa and atob

<!DOCTYPE html>
<html>
<body>

<p>Click the button to decode a base-64 encoded string.</p>

<button onclick="myFunction()">Try it</button>

<p><strong>Note:</strong> The atob() method is not supported in IE9 and earlier.</p>

<p id="demo"></p>

<script>
function myFunction() {
    var str = "Hello World!";
    var enc = window.btoa(str);
    var dec = window.atob(enc);

    var res = "Encoded String: " + enc + "<br>" + "Decoded String: " + dec;
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

function getApplication($http) {
    this.getData = function(application,name) {
      return $http({
        method : 'GET',
        url : http://localhost:8080/app/rest/+ 'app/' +  window.btoa(name)
      }).then(function successCallback(response) {
        return response.data;
      }, function errorCallback(response) {
        console.log(response.statusText);
      });
    }
  }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.