无法从Ionic 3调用Wcf Post方法

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


梦里花落0921
浏览 177回答 1
1回答

婷婷同学_

我认为问题出在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 };
打开App,查看更多内容
随时随地看视频慕课网APP