title: How to use the http post method on ionic 2 and Angular 2?
body: <p>I am now creating the Ionic 2 app to register and authenticate to Stormpath. When I registered the user I used the http post method.
  Following function is in provider there.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>register(username: string, email: string, password: string, givenname: string, surname: string){
      var headers = new Headers();
      headers.append('content-type', 'application/json;charset=UTF-8');
      headers.append('Access-Control-Allow-Origin','*');
      let options= new RequestOptions({headers: headers});
    
      var url = 'https://api.stormpath.com/v1/tenants/1QI0gxrvZNfYAFsamRTwbf/accounts';
  
      var data = JSON.stringify({
        surname: surname,
        username: username,
        givenName: givenname,
        email: email,
        password: password
      });
  
      this.http.post(url, data, options).map(res=&gt;res.json()).subscribe(data=&gt;{
        console.log(data)
      }, err=&gt;{
        console.log("Error!:", err.json());
      });
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>And using this function code is as following.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>signup(form){
  
      console.log('Pressed Signup button.')
  
      let username = form.value.username,
        email = form.value.email,
        password = form.value.password,
        givenName = form.value.givenName,
        surname = form.value.surname;
  
      this.stormpathService.register(username, email, password, givenName, surname);
  
      this.navCtrl.pop();
    }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The HTML file is :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;ion-content padding&gt;
    &lt;form #signupForm="ngForm" (ngSubmit)="signup(signupForm)"&gt;
      &lt;ion-list style="margin-bottom: 25%;"&gt;
        &lt;ion-item&gt;
          &lt;ion-label floating&gt;GivenName&lt;/ion-label&gt;
          &lt;ion-input [(ngModel)]="givenName" name="givenName" type="text" required=""&gt;&lt;/ion-input&gt;
        &lt;/ion-item&gt;
        &lt;ion-item&gt;
          &lt;ion-label floating&gt;SurName&lt;/ion-label&gt;
          &lt;ion-input [(ngModel)]="surname" name="surname" type="text" required=""&gt;&lt;/ion-input&gt;
        &lt;/ion-item&gt;
        &lt;ion-item&gt;
          &lt;ion-label floating&gt;Username&lt;/ion-label&gt;
          &lt;ion-input [(ngModel)]="username" name="username" type="text" required=""&gt;&lt;/ion-input&gt;
        &lt;/ion-item&gt;
  
        &lt;ion-item&gt;
          &lt;ion-label floating&gt;Email&lt;/ion-label&gt;
          &lt;ion-input [(ngModel)]="email" name="email" type="text" &gt;&lt;/ion-input&gt;
        &lt;/ion-item&gt;
  
        &lt;ion-item&gt;
          &lt;ion-label floating&gt;Password&lt;/ion-label&gt;
          &lt;ion-input [(ngModel)]="password" name="password" type="password" required=""&gt;&lt;/ion-input&gt;
        &lt;/ion-item&gt;
      &lt;/ion-list&gt;
  
      &lt;div style="margin-bottom: 8%;"&gt;
        &lt;button ion-button type="submit" color="light" full &gt; Sign up &lt;/button&gt;
      &lt;/div&gt;
  
    &lt;/form&gt;
  &lt;/ion-content&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Error screen is :
  <a href="https://i.stack.imgur.com/iQR6P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iQR6P.png" alt="enter image description here"></a></p>
  
  <p>Why I don't get response from stormpath server?</p>