我从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发布请求。我从其他客户/邮递员那里得到了很好的回应。
婷婷同学_
相关分类