ionic3 - Getting HttpErrorResponse in ionic3 for success response
问题描述
I am new to Ionic/Angular. Able to see success response from server in tag error.text. Please correct me where I am being wrong.
Code as follows.
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'}}
);
}
Getting error as follows:
{
"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>"
}
}
How can I get this in success response instead of err response?
解决方案
下面是正确的代码。添加了 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'
});
}
推荐阅读
- java - 从rabbitMQ接收消息时出错
- python - 使用 TensorFlow 时内存带宽不正确
- solaris - SUN Solaris 5.10 上的 HAProxy 软件
- sql - PostgreSQL中具有多列的数据透视表
- android - 从有状态类外部的小部件方法更新当前页面
- python - Python 3.7 /Mosquitto 的问题
- node.js - 无法从 github 发布电子应用程序
- mongodb - 如何在mongodb中检索嵌套数组的单个元素?
- python - 重复图像以在python中形成图案
- python - 为什么 sympy subs() 没有改变任何东西?