title: XMLHttpRequest.setRequestHeader()
body: <p>i am trying to set parameters for XMLHttpRequest.setRequestHeader()in order to be able to import csv files. Although, i am sure it's able to identity the token of the user logged in, i get an error when i submit the csv or xlxs file. What could be wrong?</p>
  
  <pre><code>//file service
     public progress$;
     public progressObserver;
     public progress : number;
     public headers:string;
  
  
      constructor (private auth:AuthenticationService) {
          this.progress$ = Observable.create(observer =&gt; {
              this.progressObserver = observer
          }).share();
      }
  
       makeFileRequest (url: string, params: string[], files: File[]) {
          return Observable.create(observer =&gt; {
              let formData: FormData = new FormData(),
                  xhr: XMLHttpRequest = new XMLHttpRequest();
  
              for (let i = 0; i &lt; files.length; i++) {
                  formData.append("uploads[]", files[i], files[i].name);
              }
  
              xhr.onreadystatechange = () =&gt; {
                  if (xhr.readyState === 4) {
                      if (xhr.status === 200) {
                          observer.next(JSON.parse(xhr.response));
                          observer.complete();
                      } else {
                          observer.error(xhr.response);
                      }
                  }
              };
  
              xhr.upload.onprogress = (event) =&gt; {
  
                  this.progress = Math.round(event.loaded / event.total * 100)
                  this.progressObserver.next(this.progress);
              };
  
  
              xhr.open('POST', url, true);
              xhr.setRequestHeader(this.headers, this.auth.token);
              xhr.send(formData);
  
  
          });
      }
  }
  //Exception
  
  ErrorHandler&lt;/ErrorHandler.prototype.handleError http://localhost:4200/main.bundle.js:44671:9
      PlatformRef_&lt;/PlatformRef_.prototype._bootstrapModuleFactoryWithZone/&lt;/&lt;.next http://localhost:4200/main.bundle.js:29085:65
      EventEmitter&lt;/EventEmitter.prototype.subscribe/schedulerFn&lt; http://localhost:4200/main.bundle.js:30598:36
      SafeSubscriber&lt;/SafeSubscriber.prototype.__tryOrUnsub http://localhost:4200/main.bundle.js:632:13
      SafeSubscriber&lt;/SafeSubscriber.prototype.next http://localhost:4200/main.bundle.js:581:17
      Subscriber&lt;/Subscriber.prototype._next http://localhost:4200/main.bundle.js:534:9
      Subscriber&lt;/Subscriber.prototype.next http://localhost:4200/main.bundle.js:498:13
      Subject&lt;/Subject.prototype.next http://localhost:4200/main.bundle.js:3046:17
      EventEmitter&lt;/EventEmitter.prototype.emit http://localhost:4200/main.bundle.js:30590:54
      NgZone&lt;/NgZone.prototype.triggerError http://localhost:4200/main.bundle.js:31404:56
      NgZone&lt;/NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner&lt;.onHandleError http://localhost:4200/main.bundle.js:31383:17
      Zone$1&lt;/ZoneDelegate&lt;/ZoneDelegate.prototype.handleError http://localhost:4200/main.bundle.js:102771:17
      Zone$1&lt;/Zone&lt;/Zone.prototype.runTask http://localhost:4200/main.bundle.js:102692:25
      ZoneTask/this.invoke http://localhost:4200/main.bundle.js:102870:28
  </code></pre>
  
  <p>//error</p>
  
  <pre><code>onChange
  file.ts:27 FileList {0: File, length: 1}
  :4200/#/dashboard/customer:1 XMLHttpRequest cannot load http://localhost:9000/api/v1/file/food. Request header field undefined is not allowed by Access-Control-Allow-Headers in preflight response.
  error_handler.js:47 EXCEPTION: 
  ErrorHandler.handleError @ error_handler.js:47
  next @ application_ref.js:272
  schedulerFn @ async.js:82
  SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
  SafeSubscriber.next @ Subscriber.js:172
  Subscriber._next @ Subscriber.js:125
  Subscriber.next @ Subscriber.js:89
  Subject.next @ Subject.js:55
  EventEmitter.emit @ async.js:74
  NgZone.triggerError @ ng_zone.js:278
  onHandleError @ ng_zone.js:257
  ZoneDelegate.handleError @ zone.js:236
  Zone.runTask @ zone.js:157
  ZoneTask.invoke @ zone.js:335
  Subscriber.js:227 Uncaught 
  SafeSubscriber.__tryOrUnsub @ Subscriber.js:227
  SafeSubscriber.next @ Subscriber.js:172
  Subscriber._next @ Subscriber.js:125
  Subscriber.next @ Subscriber.js:89
  Subject.next @ Subject.js:55
  EventEmitter.emit @ async.js:74
  NgZone.triggerError @ ng_zone.js:278
  onHandleError @ ng_zone.js:257
  ZoneDelegate.handleError @ zone.js:236
  Zone.runTask @ zone.js:157
  ZoneTask.invoke @ zone.js:335
  file.ts:20 progress = NaN
  </code></pre>