我是Ionic / Angular的新手。能够在标记error.text中看到来自服务器的成功响应。请纠正我的错误。
代码如下。
callSetMpin(otprefno){
alert(otprefno);
this.panRegistration.setMpin(otprefno)
.subscribe(
response =>{
this.setMpinResponse = response;
console.log(this.setMpinResponse);
alert("Success call");
},
err => {
console.log("Oops!-->"+JSON.stringify(err));
alert("We apologize this facility is temporarily unavailable.Please try later. ");
}
);
}
setMpin(otprefno){
let data = "SessionId=1990009769OKYLLDDP&RQDeviceId=9876543217&RQRefNo="+otprefno+"&RQLoginUserId=101068073&RQDeviceFormat=Tablet&RQOperationId=USRREGREQ&RQDeviceFamily=Android&RQTransSeq=01&RQOTP=123123&RQClientAPIVer=1.0&RQMPIN=MTExMTEx";
console.log(otprefno);
console.log(data);
return this.http.post(this.url+'/rbl/Registration2', data,
{headers:{'Content-Type':'application/json'}}
);
}
获取错误如下:
{
"headers": {
"normalizedNames": {
},
"lazyUpdate": null
},
"status": 200,
"statusText": "OK",
"url": "http://10.80.45.72:7080/rbl/Registration2",
"ok": false,
"name": "HttpErrorResponse",
"message": "Http failure during parsing for http://10.80.45.72:7080/rbl/Registration2",
"error": {
"error": {
},
"text": "<NS1:RBL xmlns:NS1=\"http://www.w3.org/2001/XMLSchema_Response_Registration2\"><NS1:HeaderEnv><NS1:RemoteIP></NS1:RemoteIP><NS1:ServerAPI></NS1:ServerAPI><NS1:RBLOperationId></NS1:RBLOperationId><NS1:LANGUAGE></NS1:LANGUAGE></NS1:HeaderEnv><NS1:SessionEnv><NS1:SessionId></NS1:SessionId><NS1:LoggedinUser></NS1:LoggedinUser><NS1:CoreSessionId1></NS1:CoreSessionId1><NS1:CoreSessionId2></NS1:CoreSessionId2><NS1:Token></NS1:Token><NS1:APPID></NS1:APPID><NS1:APPVER>2.0</NS1:APPVER><NS1:DeviceType>AndroidPhone</NS1:DeviceType></NS1:SessionEnv><NS1:RequestParams><NS1:RQOperationId>USRREGREQ</NS1:RQOperationId><NS1:RQTransSeq>01</NS1:RQTransSeq><NS1:RQLoginUserId>101068073</NS1:RQLoginUserId><NS1:RQMPIN>MTExMTEx</NS1:RQMPIN><NS1:RQDateTime></NS1:RQDateTime><NS1:RQClientAPI version=\"1.0\"/><NS1:RQDeviceFamily dname=\"Android\"/></NS1:RequestParams><NS1:STATUS><NS1:CODE>0</NS1:CODE><NS1:SEVERITY>SUCCESS</NS1:SEVERITY><NS1:MESSAGE>Registration Successful</NS1:MESSAGE><NS1:customerid>101068073</NS1:customerid></NS1:STATUS></NS1:RBL>"
}
}
如何在成功响应中获得此响应而不是错误响应?
答案 0 :(得分:0)
下面是正确的代码。添加了responseType并删除了Content-Type。
setMpin(otprefno){
let data = "SessionId=1990009769OKYLLDDP&RQDeviceId=9876543217&RQRefNo="+otprefno+"&RQLoginUserId=101068073&RQDeviceFormat=Tablet&RQOperationId=USRREGREQ&RQDeviceFamily=Android&RQTransSeq=01&RQOTP=123123&RQClientAPIVer=1.0&RQMPIN=MTExMTEx";
console.log(otprefno);
console.log(data);
return this.http.post(this.url+'/rbl/Registration2', JSON.stringify(data), {
responseType: 'text'
});
}