0

I am trying to send http request, but I face with error mentioned in title its so common but how can I handle it in my Ts component here it is(calling makecall() function):

import { Component,OnInit, ViewEncapsulation } from '@angular/core';
import {DomSanitizer } from "@angular/platform-browser";
import {Http, Response, Headers} from '@angular/http';
@Component({
  selector: 'app-twitter',
  templateUrl: '../templates/twitter.component.html',
  styleUrls: ['../styles/twitter.component.css'],
  encapsulation:ViewEncapsulation.None
})
export class TwitterComponent {
  constructor(private  domSanitizer : DomSanitizer, private http_:Http){
  }

  makecall() {
    var headers = new Headers();
    headers.append('Content-Type', 'application/X-www-form-urlencoded');
    this.http_.post('http://localhost:3000/authorize', {headers: headers}).subscribe((res) => {
      console.log(res);
    })
  }
}

this is what I see in my dev console: enter image description here

TyForHelpDude
  • 4,828
  • 10
  • 48
  • 96
  • 1
    This isn't a problem with your client. The headers need to be added in the server side. [Read about CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) – Nitzan Tomer Dec 28 '16 at 08:36
  • Possible duplicate of [Angular 2 http request with Access-Control-Allow-Origin set to \*](http://stackoverflow.com/questions/35155752/angular-2-http-request-with-access-control-allow-origin-set-to) – Nitzan Tomer Dec 28 '16 at 08:38
  • Thanks for answers but dislike for your duplicate idea if its on you nobody can share new post.. – TyForHelpDude Dec 28 '16 at 14:52

0 Answers0