angulartypescriptencodingangular-httpclient

What encoding does the 'text' response type option in HttpClient use?


When making an HTTP request like this:

return HttpClient.get("url", { headers: requestHeaders, responseType: 'text'});

What encoding is used when turning the response into a string?


Solution

  • Checking the official Angular Repository, for the Http Client we can look under common/http:

    While looking into the official repo, you can only find a mention of encodings in one particular case, as seen here:

    if (this.body instanceof HttpParams) {
      return 'application/x-www-form-urlencoded;charset=UTF-8';
    }
    

    Checking in the network tab of an Angular application, you can see that it does not specify the encoding type, when sending a request, however, the response headers of the response may include it in the content-type property if the sending server specified it.

    Like mentioned in the comments, default is utf-8, as mentioned by jonrsharpe.