这是我的问题,我有一个Web和客户端(Winform),客户端将发送带有序列化对象的数据。我的Web确实收到并返回了一个响应给客户端。但是我无法在Web上查看数据,我确实尝试过使用Deserialize对象并将其转换为string,但两者都不能工作。请帮帮我,谢谢!
这是我的代码:
客户端
private string WebApiPost(string sParam, string sJson)
{
var client = new HttpClient();
var content = new StringContent(sJson, Encoding.UTF8, "application/json");
var response = client.PostAsync(sWebAPI_URL + sParam, content).Result;
var body = response.Content.ReadAsStringAsync().Result;
return body;
}这是我的Web
public object Post([FromBody]object hL7)
{
//what should I do???
//I've tried set hL7 into string but it wont get any data;
//I've also tried deserialize it but will get 500 internal server error.
return hL7;
}这是我的WebAPI模型
public class HL7MID
{
public string LOC { get; set; }
public string COMPANY { get; set; }
}
public class HL7MID_List
{
public string sMSG { get; set; }
public List<HL7MID> data = new List<HL7MID>();
}发布于 2018-12-03 03:52:02
因为sJson与HL7MID匹配,所以可以使用该类型作为Post函数的参数,并且只需使用该类型。
public HL7MID Post([FromBody]HL7MID hL7)
{
//use hL7 here
return hL7;//also since you know the return type, changing that to HL7MID is suggested
}https://stackoverflow.com/questions/53586883
复制相似问题