Angular url plus sign converting to space

后端 未结 7 1585
梦如初夏
梦如初夏 2020-11-29 06:02

I have angular application where i want to pass plus sign + in query string like:

http://localhost:3000/page?name=xyz+manwal
7条回答
  •  感情败类
    2020-11-29 07:07

    I am using Angular 7, the + (this one "xyz+manwal") is replaced with a space (like this "xyz manwal") in the URI when it reaches to back-end code.

    encodeURI() dindn't work for me, I used encodeURIComponent() it converted + to %2B

         encodeURIComponent("xyz+manwal") => "xyz%2Bmanwal"
    

    below is the example code

        // filter = xyz+manwal
        let filterString =  encodeURIComponent(filter); // filterString = xyz%2Bmanwal
    
        return this.http.get("http://website/query-results?" + filterString ).pipe(
          retry(3),
          catchError(........)
        )
    

提交回复
热议问题