title: convert string/Text to byte array in type script
body: <p>I am Currently working on task to download file (PDF/excel/text) using secure API in my system in angular 2 (beta) version.</p>
  
  <p>I have used post API with authentication header and trying to create blob using data bytes received.</p>
  
  <p>I have tried using following code </p>
  
  <pre><code>return this.http.get(url, { headers: this.headers}).map( response =&gt; response.blob())
  </code></pre>
  
  <p>But, i got the error that blob method is not implemented in angular 2 HTTP.</p>
  
  <p>so i am trying following code where i need to convert string to byte array.</p>
  
  <pre><code>return this.http.get(Configuration.API_URL + url, { headers: this.headers }).map(
              response =&gt; {
                  var bytes = [];
  
                  var utf8 = encodeURIComponent(response.text());
                  for (var i = 0; i &lt; utf8.length; i++) {
                      bytes.push(utf8.charCodeAt(i));
                  }    
                  var data = new Blob([bytes], { type: 'application/pdf' });
                  var fileURL = URL.createObjectURL(data);
                  window.open(fileURL);
              }
          );
  </code></pre>
  
  <p>here i am facing some issue with the bytes array. Byte array is not same as the one sent by the API.</p>
  
  <p>Need help in either converting string to byte array  or using blob in angular 2 HTTP get request.</p>