title: How Angular2 Http request can return body as binary?
body: <p>I have a url that return the html content with charset=iso-8859-7 which means angulars http request convert the data to utf8 by default and i am unable to encode them back in iso-8859-7 properly. After a lot of searching i found out that many people had the same issue and most of the answers were to change the charset in the server, something that i'm unable to do as the server doesn't belong to me.</p>
  
  <p>So the question is how can HTTP request return binary so i can encode them to iso-8859-7 string?</p>
  
  <p><strong>EDIT - SOLUTION:</strong><br>
  What i finally did was to to use <strong>TextDecoder</strong> and {<strong>responseType: ResponseContentType.ArrayBuffer</strong>} at <em>RequestOptions</em>. Here is an example to help anyone who is trying to parse html pages and decode them into the right encoding. Hope to help all the guys who tried this in a project which is using Angular2 like Ionic2.</p>
  
  <pre><code>public parser() {
      // Set content type
      let headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded;'});
      // Create a request option, with withCredentials for sending previous stored cookies
      let options = new RequestOptions({
        withCredentials: true,
        headers: headers,
        responseType: ResponseContentType.ArrayBuffer
      });
  
      return this.http.get('https://blablablablabla', options) // ...using get request
        .map((res: any) =&gt; {
  
          var string = new TextDecoder('iso-8859-7').decode(res._body);
  
          var parser = new DOMParser();
          var htmlDoc = parser.parseFromString(string, "text/html");
  
          console.log(string)
  
          ..... blabla blabla doing some stuff here .....
        })
        .catch((error: any) =&gt; Observable.throw(error || 'Server error'));
  }
  </code></pre>