我从Ionic请求wcf post方法,但出现错误{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":null,"ok":false,"name":"HttpErrorResponse","message":"Http failure response for (unknown url): 0 Unknown Error","error":{"isTrusted":true}}我的WCF Post方法是 public Stream GetMonthWiseAttendance(InputMonthwise input) { var SerializeObject = new JavaScriptSerializer(); var temp = context.MobAttendMonthWiseStudentAttaindance(input.StudentMainId, input.InstituteId, input.Yearid).ToList(); string jsonClient = SerializeObject.Serialize(temp); WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"; WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With,Accept"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "GET, PUT, POST"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Max-Age", "1728000"); return new MemoryStream(Encoding.UTF8.GetBytes(jsonClient)); }我的离子码是callPost() { let headers = new HttpHeaders(); headers.append('Content-Type', 'application/json'); headers.append('Access-Control-Allow-Origin' , '*'); headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT'); let data=JSON.stringify({userName:'Rameshwar',InstituteId:1191,Yearid:135,StudentMainId:135 });有了这个离子代码,我能够调用php的post方法,但是调用wcf方法却出错了。我也可以使用相同的标头调用Wcf的Get方法以进行响应我还与Postman Rest客户端一起检查了该wcf发布请求。我从其他客户/邮递员那里得到了很好的回应。
1 回答
婷婷同学_
TA贡献1844条经验 获得超8个赞
我认为问题出在Ionic Code中,无需整理发布数据,由ionic在内部进行管理。
let data=JSON.stringify({userName:'Rameshwar',InstituteId:1191,Yearid:135,StudentMainId:135 });
改成,
let data={userName:'Rameshwar',InstituteId:1191,Yearid:135,StudentMainId:135 };
- 1 回答
- 0 关注
- 176 浏览
添加回答
举报
0/150
提交
取消