Argument of type '{headers:Headers;}' is not assignable to parameter of type 'RequestOptionsArgs'.Property 'null' is missing in type '{headers:Headers;}'

in ionic 2 …call web api using post method that time facing this error when I wrote { headers:headers }
this is my code

error : Argument of type ‘{headers:Headers;}’ is not assignable to parameter of type ‘RequestOptionsArgs’.Property ‘null’ is missing in type ‘{headers:Headers;}’

var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    //let options = new RequestOptions({ headers: headers });

    let postParams = {
        type: 'insertbranch',
        vendorid: 1,
        imgcode: ' ',
        address: 'varachhaSurat',
        latitude: '0',
        longitude: '0',
        branchmobile: '9853624221',
        gstno: '0'
    }

    this.http.post("MY URL", postParams, { headers: headers })
        .subscribe(data => {
            console.log(data['_body']);
        }, error => {
            console.log(error);// Error getting the data 
        });

You don’t need custom headers here. Simply create the body as a URLSearchParams and Angular will handle the rest.

1 Like

the same problem here @shivani8710

1 Like

Import this:
import { Headers } from ‘@angular/http’;

2 Likes