我遇到的問題是,現在我有一個web api和一個client(winform)
client端會create一組data傳到web api,我的web api有收到一個JObject檔,裏面也有client端資料,但是我要怎麽提取裏面的data並顯示在我的web api?
我用過反序列化,web api會直接回傳500 internal server error...
以下是我的code
//client端
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 API
public object Post([FromBody]object hL7)
{
//這裏我收到是一整個object,試過deserialize和强轉成string都不行,兩個都會回傳500 internal server error
return hL7;
}
//Web API controller
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>();
}
提供給您參考看看
public class request_login
{
public string email { get; set; }
public string password { get; set; }
}
public class login_root
{
public string status { get; set; }
}
[HttpPost]
public object login([FromBody]request_login login)
{
login_root root = new login_root();
if (login.email == "user@isp.com.tw" && login.password="123456")
{
root.status = "OK";
}
else
{
root.status = "Error";
}
return root;
}