【发布时间】:2019-06-11 04:30:47
【问题描述】:
我有一个 API 接受 get 方法中的 [FromBody] 那么我如何调用这个 Get 方法
我的 API 是
[BearerAuth]
[HttpGet]
public Dictionary<long, string> GetEmployees([FromBody] Employee obj)
{
Dictionary<long, string> dic = new Dictionary<long, string>();
//Some Implemenation
return dic;
}
现在我正在尝试从 Windows 应用程序调用它
using (WebClient webRequest = new WebClient())
{
Employee emp = new Employee { EmpId = 1, Name = "Mohan", Gender = "Male", MobileNo = "9560498289", Salary = 50000 };
string url = APIUrl_2 + "/APITest/GetMethod_FromBody";
//string JsonString = JsonConvert.SerializeObject(emp);
//ASCIIEncoding encoding = new ASCIIEncoding();
//byte[] data = encoding.GetBytes(JsonString);
WebRequest request = WebRequest.Create(url);
request.Method = "GET";
request.Headers["Authorization"] = "Bearer " + "AuthKey";
using (WebResponse response = request.GetResponse())
{
}
}
请谁能帮我在 FromBody 中发送员工数据,它被调用但 Employee 为空。
我只能通过get方法来做。
提前致谢
【问题讨论】: