c# - 无法从另一个天蓝色函数运行 HttpTrigger Azure 函数
问题描述
这是 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);
但我收到以下错误:
No MediaTypeFormatter is available to read an object of type 'Query' from content with media type 'text/plain'.
我该如何解决?请帮忙!!!
解决方案
看起来问题是您发送的请求未指定其内容类型,并且默认为text/plain
. 由于没有Content-type header
,因此该函数不知道您要发送哪种类型的内容。您应该添加Content-Type header
带有值的 a application/json
。
Accept request-header 字段可用于指定响应可接受的某些媒体类型。
Content-Type entity-header 字段指示发送给接收者的实体主体的媒体类型,或者在 HEAD 方法的情况下,如果请求是 GET,则本应发送的媒体类型。
资料来源:接受标头与内容类型标头
推荐阅读
- api - 如何在 laravel 单元测试中测试功能
- css - Not able to make responsive design due to "margin" as inline css
- laravel - 在 Laravel 中将日期保存为字符串
- r - using cumax for making a new column
- javascript - How do I get docx.js children method to work?
- sql - how to get the rows which doesn't have data
- php - 如何仅在 Internet Explorer 中加载网站而不在其他浏览器上打开
- azure - Azure IoT 中心和接收任何东西
- node.js - Nodejs - SSL 握手日志
- jquery - 如何动态添加按钮