0

I am having an application using Angular, which communicates with backend via rests. I am facing a problem with encoding of my questionares.

Angular part:

  searchCase(searchText: string): Observable<Case[]> {
    const encodedText = encodeURIComponent(searchText);
    return this.http.get<Case[]>(`${this.baseUrl}/case/search/${encodedText}`);
  }

Rest:

public List<Case> searchCase(
        @PathParam("searchedText") String searchedText) {
    return caseManagement.searchCase(searchedText);
}

For any input, this works totally fine, except for backslash. Then, it does not even reach my backend rest part. How can I go over it?

3
  • 1
    Look here stackoverflow.com/questions/12555230/… . Actually it is considered as a part of your URL, so follow the steps of @sachleen and it will work fine! Commented Nov 13, 2018 at 14:06
  • Can you give us any string examples? Commented Nov 13, 2018 at 15:33
  • @AndrejBuday an example would be "12\65" - just a random string including backslash Commented Nov 13, 2018 at 21:50

1 Answer 1

0

It turned out that it was enough to use btoa instead:

searchCase(searchText: string): Observable<Case[]> {
    const encodedText = btoa(searchText);
    return this.http.get<Case[]>(`${this.baseUrl}/case/search/${encodedText}`);
  }

And then decode it on backend side and seems to work totally fine.

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.