当我运行它给了我一个500 error.Since上午还是新的网页API主题的客户端代码,我真的很感激的帮助,以确定哪些是我的失误。
using (HttpClient client = new HttpClient())
{
ObjHeader.listRtnTalleySheetHeader = lstRtnTalleySheetHeader;
ObjHeader.listRtnTalleySheetDetail = lstRtnTalleySheetDetail;
client.BaseAddress = new Uri("http://---service---");
var url = "api/config/InsertTalleydetail/";
var alldetails = Newtonsoft.Json.JsonConvert.SerializeObject(ObjHeader);
HttpContent content = new StringContent(alldetails, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url, content);
if (response.IsSuccessStatusCode)
val = "Ok";
else
val = "No";
}
return val;
其中ObjHeader是clsAllTalleyHeaderDetail ObjHeader = new clsAllTalleyHeaderDetail();
clsAllTalleyHeaderDetail是
public class clsAllTalleyHeaderDetail
{
public ObservableCollection<clsTalleySheetHeader> listRtnTalleySheetHeader { get; set; }
public ObservableCollection<clsTalleySheetDetail> listRtnTalleySheetDetail { get; set; }
}
然后我的Web API
[HttpPost]
public HttpResponseMessage InsertTalleydetail([FromBody] clsAllTalleyHeaderDetail obj)
{
return todoService.InsertTalleydetail(obj.listRtnTalleySheetHeader , obj.listRtnTalleySheetDetail );
}