How encode special character without causing error in httpclient angular

Discussão em 'Angular' iniciado por COD3, Setembro 25, 2024.

  1. COD3

    COD3 Guest

    I have a data id value STUDENT/STUD01 then I'm trying to encode the "/" but it cause an error in httpclient if its not encoded it will create a new path.

    what I try is use the encodeURI(data.id) and encodeURIComponent(data.id)

    const data = cloneDeep(this.form);
    let url = this.getAPI();
    url += `/${encodeURI(data.id)}`

    this.http.post(url, data).subscribe((.) => {....});


    or

    const data = cloneDeep(this.form); let url = this.getAPI(); url += `/${encodeURIComponent(data.id)}`

    this.http.post(url, data).subscribe((.) => {....});


    but it cause an error which

    Request URL: https://localhot:8080/api/list/STUDENT%STUD01 Referrer Policy: strict-origin-when-cross-origin

    Continue reading...

Compartilhe esta Página