Error calling REST service - Url Encode

Asked

Viewed 99 times

1

When trying to make an HTTP GET call, the service returns an error 500 because querystring should use the + encoded symbol instead of spaces. Ex.: LOS+ANGELES = LOS%ANGELES

autocomplete(term: string){
    var url = this.serviceUrl + 'autocomplete?query=' + term + '&limit=5';
    console.log(url);
    return this.http
        .get(url, { headers: this.headers })
        .map((res: Response) => res.json());
}

Error returned when trying to make a call by passing some text with space, e.g.: los Angeles.

status
:
500
statusText
:
"Internal Server Error"
type
:
2
url
:
"https://api.test.sabre.com/v1/lists/utilities/geoservices/autocomplete?query=los%20a&limit=5"
_body
:
"{"status":"Unknown","reportingSystem":"RAF","timeStamp":"2017-09-21T12:03:40+00:00","type":"Application","errorCode":"ERR.RAF.APPLICATION","instance":"raf-darhlc006-9080","message":"Illegal character in query at index 75
  • I recommend you use the Postman program to test your requests. If it works on it, you will know how a request is made this way. Looking at it this way I could not find any error, just testing even to know. Good luck there

  • I only use the Postman for testing!

  • what happens is if I pass a value in the url with space, eg:LOS ANGELES, the string is converted to LOS%20ANGELES and the service returns an error 500, because it does not accept this type of Find.

  • And it’s working this way that you’re making the requisition there at Postman?

  • Yes, look at that crazy, I think I understood better, when I make the request I need to pass in place of the spaces the symbol + porem with ENCODE understands?

  • Yes, I get it. Google puts this + symbol a lot in the searches.

  • What type of Content-Type you are using in the request?

  • @Renatodiniz application/json

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.