【发布时间】:2018-02-11 15:17:01
【问题描述】:
我有一个问题,我无法检索 JSON 对象的 POST 语句的正文。这是执行http-Request时调用的函数:
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "HttpTriggerCSharp/name/{name}")]HttpRequestMessage req, string name, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
string output = JsonConvert.SerializeObject(req.Content.ToString());
// Fetching the name from the path parameter in the request URL
return req.CreateResponse(HttpStatusCode.OK, output);
}
我正在使用 Postman 和以下 URL 执行 POST:http://localhost:7071/api/HttpTriggerCSharp/name/test
在 Header 中我写了“Content-Type: application/json”,Body 看起来像这样:
{
"Benutzer":"Nenad",
"Passwort":"test"
}
我的结果是这样的:"\"System.Net.Http.StreamContent\""
感谢您的帮助!
【问题讨论】:
-
我认为你应该使用
httpResponse.Content.ReadAsString(); -
您必须先将您的流读入一个字符串,然后将流直接提供给序列化器
标签: c# json httprequest body-parser