c# - 无法从另一个azure函数运行HttpTrigger Azure函数

标签 c# azure http-post azure-functions

这是 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/jsonContent-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.

来源:Accept header vs Content-Type Header

关于c# - 无法从另一个azure函数运行HttpTrigger Azure函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51135809/

相关文章:

c# - 计数记录始终为 1

c# - 如何在 C# 中检测 DLL 的进程退出

asp.net - 在 ASP.NET 应用程序中处理大型并发 HTTP POST

java - 异步任务 : Implementing executeOnExecutor() thread class in AudioTrack

c# - 通过 html 敏捷包获取标题标签

c# - 对 sqlcommand.executescalar 使用声明

azure - 在托管磁盘上设置 Azure Service Fabric 群集

azure - 如何使用不同的帐户将存储容器添加到Azure?

powershell - 如何使用 powershell 在 Azure AD 中自动注册 Office 365 应用程序?

android - 通过应用程序通过 HttpPost 登录网站