1
votes

Here is function.json snippet

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "query",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get",
        "post"
      ]

Here is my run.csx file:

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)
{

Now I need to call this Http triggered function from another function. I am doing:

var url = "https://azurefunction...";
var content2 = new StringContent(string.Format("{{\"AdvanceDays\":7}}"));
var response = await client.PostAsync(url,content2);

But I get the following error: No MediaTypeFormatter is available to read an object of type 'Query' from content with media type 'text/plain'.

How do I fix this? Please help!!!

1

1 Answers

2
votes

Looks like the issue is that the request you're sending doesn't specify its content-type, and it defaults to text/plain. Since there's no Content-type header, the function doesn't know which type of content you're sending. You should add a Content-Type header with the value application/json.

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.

Source: Accept header vs Content-Type Header