title: Adding header to http.get in Angular 6
body: <p>I'm trying to modify the working example from deerawan to include header for another website that requires a header. I was given the solution below and it seems to work perfectly. But when I add <code>subscribe()</code>, it still works, but I get exception in console: </p>
  
  <p>What should I do to fix this warning message?  Thank you.</p>
  
  <p><strong>Original code:</strong></p>
  
  <pre><code>export class UserService {
  
    private serviceUrl = 'https://jsonplaceholder.typicode.com/users';
  
    constructor(private http: HttpClient) { }
  
    getUser(): Observable&lt;User[]&gt; {
      return this.http.get&lt;User[]&gt;(this.serviceUrl);
    }
  }
  </code></pre>
  
  <p><strong>Solution code:</strong></p>
  
  <pre><code>export class NWSForecast {
    private config = {
      headers: {
        'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36'
      }
    };
  
    private serviceUrl = 'https://api.weather.gov/gridpoints/OKX/36,38/forecast';
  
    constructor(private http: HttpClient) { }
  
    getUser(): Observable&lt;any&gt;  {
      // first argument is URL, put config as second argument
      return this.http.get&lt;any&gt;(this.serviceUrl, this.config);
    }
  }
  </code></pre>
  
  <p><strong>Modified solution in order to capture response. But it has exception:</strong></p>
  
  <pre><code>export class AppComponent {
    private config = {
      headers: {
        'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36'
      }
    };
    weathers: any;
    private serviceUrl = 'https://api.weather.gov/gridpoints/OKX/36,38/forecast';
  
    constructor(private http: HttpClient) { }
  
    getWeather() {
      this.http.get&lt;Weather&gt;(this.serviceUrl, this.config).subscribe(
        val =&gt; {
          this.weathers = val;
        console.log('this.weather ====&gt; ', this.weathers);
        });
      }
  }
  </code></pre>
  
  <p>The error message in console:
  <code>Refused to set unsafe header "User-Agent" http.js:1436</code></p>