Harish Rana
Harish Rana

Reputation: 157

Error: Uncaught (in promise): Response with status: 0 for URL: null status: 404

when ever I am trying hit a post request url I am having this error

Error: Uncaught (in promise): Response with status: 0  for URL: null
    at c (http://localhost:8100/build/polyfills.js:3:19752)
    at c (http://localhost:8100/build/polyfills.js:3:19461)
    at http://localhost:8100/build/polyfills.js:3:20233
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)
    at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33)
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581)
    at r.runTask (http://localhost:8100/build/polyfills.js:3:10834)
    at o (http://localhost:8100/build/polyfills.js:3:7894)
    at e.invokeTask [as invoke] (http://localhost:8100/build/polyfills.js:3:16823)
    at p (http://localhost:8100/build/polyfills.js:2:27648)

My Typescript code is

public getCategory(){
        console.log('test');
        return new Promise((resolve, reject) => {
        let header = new Headers();
        header.append('Content-Type', 'application/x-www-form-urlencoded');
        let curr_page = { "currentPage":1,"pageSize":2 };
        // var page_size = 5;
        this.http.post(this.db,JSON.stringify(curr_page),{headers: header}).map(res=>res.json())
        .subscribe(res=>{
          console.log(res);
          resolve(res);
        }, (err) => {
          reject(err);
        });
    });
  }

but when I am trying to hit this url on Postman app then its working, Waiting for Help.

Upvotes: 0

Views: 1105

Answers (1)

Ehasanul Hoque
Ehasanul Hoque

Reputation: 640

here is the signature of http post method in angular

post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;

You can try the following way

var options = new RequestOptions();
options.headers = new Headers();
options.headers.append( 'Content-Type', 'application/x-www-form-urlencoded');
let curr_page = { "currentPage":1,"pageSize":2 };
    // var page_size = 5;
    this.http.post(this.db,JSON.stringify(curr_page),options).map(res=>res.json())
    .subscribe(res=>{
      console.log(res);
      resolve(res);
    }, (err) => {
      reject(err);
    });

Upvotes: 1

Related Questions