title: HTTPClient POST tries to parse a non-JSON response
body: <p>I'm trying to make a request in Angular and I know that the HTTP response will <strong>not be in JSON</strong> but in text. However, Angular seems to be expecting a JSON response since the error is the following:</p>
  
  <blockquote>
    <p>SyntaxError: Unexpected token &lt; in JSON at position 0 at JSON.parse
    () at XMLHttpRequest.c</p>
  </blockquote>
  
  <p>As well as</p>
  
  <blockquote>
    <p>Http failure during parsing for <a href="http://localhost:9" rel="noreferrer">http://localhost:9</a>...</p>
  </blockquote>
  
  <p>This is the post method:</p>
  
  <pre><code>return this.http.post(this.loginUrl, this.createLoginFormData(username, password), this.httpOptions)
    .pipe(
      tap( // Log the result or error
        data =&gt; console.log(data);
        error =&gt; console.log(error)
      )
    );
  </code></pre>
  
  <p>and the headers.</p>
  
  <pre><code>private httpOptions = {
  
    headers: new HttpHeaders({
      'Accept': 'text/html, application/xhtml+xml, */*',
      'Content-Type': 'application/x-www-form-urlencoded',
      responseType: 'text'
    },
  
  ) };
  </code></pre>
  
  <p>I thought that <code>responseType: 'text'</code> would be enough to make Angular expect a non JSON response.</p>