1

Im having a problem converting the curl command below into a ionic2/angular2 code.

Im not sure if the Authorization header is passed on to the backend server since the error looks like this below not a invalid token error.

{"detail":"Authentication credentials were not provided."}

Any help is very much appreciated.

Curl Command

curl -v -H"Content-Type: application/json" -H"Authorization: Token xxxxxxxx" -XPOST -d'{"status": "True"}' https://xxx/xx/xxx/status/

Ionic2

var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json' );
headers.append('Authorization', 'Token ' + "xxxxxxxx");
let options = new RequestOptions({ headers: headers });
let postParams = {
  status: "True"
}
return new Promise(resolve => {
  this.http.post(Uri, postParams, options).subscribe(data => {
    resolve(data);
  }, err => {
    console.log(err.json());
  });
});
Claies
  • 22,124
  • 4
  • 53
  • 77
user799451
  • 81
  • 12
  • your syntex seems to be ok https://stackoverflow.com/a/4423097/5621827 can help you to check requestion headers – jitender Oct 10 '17 at 04:01

0 Answers0