0

我正在创建从 API 检索/写入数据的应用程序,并将 http native 用于 android 应用程序。获取方法现在可以了。但是,当我使用 post 和 patch 来保存数据时,该方法还不起作用。

您能否指导我如何使用 POST 保存数据?这是我的代码如下:

在 service.ts 中,

 updateProfile(userProfile) {
    console.log("UpdatePro_"+JSON.stringify(userProfile));
    return this.http.patch(this.mcs.mobileBackend.getCustomCodeUrl(mcsConfig.environment + '_api_care/my/profile'), userProfile, this.getMcsHeadersString());
  }

getMcsHeadersString() {
    var cheaders = {};
    for (let key in this.mcs.mobileBackend.getHttpHeaders()) {
      cheaders[key]= this.mcs.mobileBackend.getHttpHeaders()[key];
    }
    //console.log("STring_HeaderKey_"+cheaders['_keys']+"HeaderValue_"+cheaders['_values']);
    delete cheaders['_keys'];
    delete cheaders['_values'];
    return cheaders;
  } 

在 profileedit.ts

save() {

    this.mcsService.updateProfile(this.userProfile).then((res) => {

      console.log("testUp"+this.userProfile);
      this.router.navigate(['menu/profile']);
    }, (err) => {
      console.log("Invalid_"+err.error);
      this.presentAlert(err.error);
    }
    );
  }

错误消息显示如下:

{"message":"Custom Code Problem in callback: RangeError: Invalid status code: 0"}

Custom Code Problem in callback: 
request:
 patch  /profile
caused unhandled error:
 RangeError: Invalid status code: 0
    at ServerResponse.writeHead (_http_server.js:192:11)
    at ServerResponse.res.writeHead (/u01/app/mobile_ccc/mcs-node-router/mcs-node-server.js:765:35)
    at ServerResponse._implicitHeader (_http_server.js:157:8)
    at ServerResponse.OutgoingMessage.end (_http_outgoing.js:571:10)
    at ServerResponse.send (/u01/app/mobile_ccc/node-configurations/6.10/node_modules/express/lib/response.js:205:10)
    at getMyProfileRow.then.catch (/u01/app/mobile_ccc/custom_code_modules/01fead32-6294-4f8e-8dcb-fa405af7d75a_6/rest_api/custom/my/router_dbtable.js:545:36)
4

1 回答 1

0

答案是我需要解析 JSON obj,例如 this.userProfile.user_name= JSON.parse(mcsService.userProfile).user_name;

于 2019-05-28T00:33:48.693 回答