【问题标题】:"Http failure response for (unknown url): 0 Unknown Error",“(未知 url)的 Http 失败响应:0 未知错误”,
【发布时间】:2019-01-22 09:40:50
【问题描述】:

我直接与设备通信。

当我输入浏览器IP时

http://192.168.12.1/myconfig?pass=1&name=mywifi&passIS=87654321

在浏览器中显示此消息:config is ok。

现在,在我的项目中,我创建了一个输入值的表单。在 service.ts 中,我创建了 POST 方法,如下所示:

public createConfiguration(NewConfiguration: Configuration) {
    let headers = new Headers();
    headers.append('Content-Type', 'application/Json');
    let body = NewConfiguration.generateUrlencodedParameters();
    let url =  ('http://192.168.12.1/myconfig?')
    this.httpclient.post(url, body, {
       }).subscribe(d=>{
      console.log('response create newconfiguration', d)

    })
  }

这个函数显示错误:

JS: ERROR {
JS:   "headers": {
JS:     "normalizedNames": {},
JS:     "lazyUpdate": null,
JS:     "headers": {}
JS:   },
JS:   "status": 0,
JS:   "statusText": "Unknown Error",
JS:   "url": null,
JS:   "ok": false,
JS:   "name": "HttpErrorResponse",
JS:   "message": "Http failure response for (unknown url): 0 Unknown Error",
JS:   "error": {
JS:     "originalStack": "Error: java.io.EOFException\n    at new c (file:///data/data/org.nativescript.myapp/files/app/vendor.js:1:1217697)\n    at file:///data/data/org.nativescript.myapp/files/app/vendor.js:1:1083743\n    at Object.onComplete (file:///data/data/org.nativescript.myapp/files/app/vendor.js:1:1084864)",
JS:     "zoneAwareStack": "Error: java.io.EOFException\n    at new c (file:///data/data/org.nativescript.myapp/files/app/vendor.js:1:1217697)\n    at file:///data/data/org.nativescript.myapp/files/app/vendor.js:1:1083743\n    at Object.onComplete (file:///data/data/org.nativescript.myapp/files/app/vendor.js:1:1084864)"
JS:   }
JS: }

消息config is ok 在正文中。

请问您知道如何解决此错误吗?

【问题讨论】:

  • 控制台正文并确保您的查询参数必须以正确的形式发送。
  • 我发送正确的查询参数

标签: angular typescript http httpclient nativescript


【解决方案1】:

修改你的代码如下:

// in service.ts file

public createConfiguration(NewConfiguration: Configuration) {
    let headers = new Headers();
    headers.append('Content-Type', 'application/Json');
    let body = NewConfiguration.generateUrlencodedParameters();
    let url =  ('http://192.168.12.1/myconfig?')
    this.httpclient.post(url, body, {});  // <-- you need to subscribe in component.ts file
  }
  
  
  //in compoenent.ts file  
  
  public callerMethod(){  //<- method which calls createConfiguration() service
  
  // srvcObj -> your service object name , paylaod -> input you are sending to servoce method
  this.srvcObj.createConfiguration(payload).subscribe((result:any)=>{
  
           console.log('response create newconfiguration', result);
  },
  (error)=>{
     console.log('got error',error);
  }
  );
  
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    相关资源
    最近更新 更多