title: Adding custom headers to form submit
body: <p>I am using angular 4 for one of my projects and i have a method which creates a form element dynamically and submits it</p>
  
  <pre><code>postToUrl(path, params, method) {
          method = method || 'post';
          let form = document.createElement('form');
          form.setAttribute('method', method);
          form.setAttribute('action', path);
          for (let key in params) {
              if (params &amp;&amp; params.hasOwnProperty(key)) {
                  let hiddenField = document.createElement('input');
                  hiddenField.setAttribute('type', 'hidden');
                  hiddenField.setAttribute('name', key);
                  hiddenField.setAttribute('value', params[key]);
                  form.appendChild(hiddenField);
              }
          }
          document.body.appendChild(form);
          form.submit();
          setTimeout(() =&gt; {
              document.body.removeChild(form);
          }, 2000);
      }
  </code></pre>
  
  <p>What i want to do is set a custom header to the request so that i can attach all the headers required by the server. Is there any way i can write a common interceptor for this so that i don't have to repeat the lines. Please help. Any help is appreciated.</p>