[英]ASP.NET Core API POST parameter is always null while hit from python
我有一个 jsondata 存储在一个文件中,该文件充当另一个 post call 的参数,下面提到了我在 python 代码中的尝试
files = {'file': open('GetCat.json', 'rb')}
headers = { 'Accept' : 'application/json', 'Content-Type' : 'application/json'}
r = requests.post("http://localhost:69302/Ass/Server/GetCategoryList", files=files, headers=headers)
但是当我尝试点击我的 C# 代码时,身体总是作为 null 传递,我对 C# 代码的尝试如下所述
[HttpPost]
[Route("GetCategoryList/")]
public adminquestion GetQuestionaireList([FromBody] adminquestion questionsList )
{
adminquestion questionList;
try
{
questionList = _adminService.GetQuestionaireList(questionsList);
}
catch (Exception ex)
{
throw ex;
}
return questionList;
}
我面临的问题是每次参数都是null,请指导我面对一个拦截器,谢谢
我的猜测是,这不是 C# 代码的错。 这似乎是pyhton代码的错。
看这里,仔细阅读file
属性:
可选的。 要发送到指定 url 的文件字典
文件的内容可能是json
,但我认为文件本身将作为字节流传输。
所以你应该阅读文件的内容并使用json
属性。
r = requests.post("http://localhost:69302/Ass/Server/GetCategoryList", json=jsonContentFromFile, headers=headers)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.