这是 function.json 片段
{
"bindings": [
{
"authLevel": "function",
"name": "query",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
这是我的 run.csx 文件:
public class Query{
public double AdvanceDays{get;set;}
}
public static async Task<HttpResponseMessage> Run(Query query,entity Entity,HttpRequestMessage req, TraceWriter log, IEnumerable<dynamic> inputDocument)
{
现在我需要从另一个函数调用这个 Http 触发函数。我正在做:
var url = "https://azurefunction...";
var content2 = new StringContent(string.Format("{{\"AdvanceDays\":7}}"));
var response = await client.PostAsync(url,content2);
但是我收到以下错误:
没有 MediaTypeFormatter 可用于从媒体类型为“text/plain”的内容中读取“Query”类型的对象。
我该如何解决这个问题?请帮忙!!!
最佳答案
问题似乎在于您发送的请求未指定其内容类型,并且默认为 text/plain
。因为没有Content-type header
,该函数不知道您要发送哪种类型的内容。您应该添加一个值为 application/json
的 Content-Type header
。
The Accept request-header field can be used to specify certain media types which are acceptable for the response.
The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET.
关于c# - 无法从另一个azure函数运行HttpTrigger Azure函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51135809/