错误:未捕获(承诺):状态为0的URL响应:空状态:404

时间:2019-01-23 06:15:08

标签: angular typescript ionic-framework ionic3 typescript2.0

当我尝试点击发布请求网址时,我遇到此错误

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)

我的打字稿代码是

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);
        });
    });
  }

但是当我试图在Postman应用程序上访问此URL时,它便开始工作,正在等待帮助。

1 个答案:

答案 0 :(得分:1)

这是用角度的http post方法的签名

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

您可以尝试以下方式

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);
    });