Content being returned by HttpMessageResponse is blank/empty after being explicitly set
I have created a WebApi with the latest .net Framework 4.6.1 and am trying to pass back some TwiML back to Twilio (not really the issue/problem as I have the problem even with plain text).
For some reason, no matter what I do, when setting the Content for a HttpResponseMessage that content is not passed back to the caller. I have used Postman and Fiddler, and while the content header is showing after setting the content via StringContent, the actual content I am trying to pass back does not. It does however seem to be showing in the ContentLength.
I am really confused and may be overlooking something very simple, but over a day has been wasted so far.
I am showing just text trying to be sent back with nothing fancy and I get nothing back! In my real use case I am trying to pass back a string of XML as a type of text/xml. But even a basic text string does not come back!!
Any help is greatly appreciated, this has totally stumped me.
public HttpResponseMessage Post(TwilioCall call)
{
...
...
...
var responseMessage = new HttpResponseMessage
{
Content = new StringContent("Representative Text Here")
};
return responseMessage;
}
The following is returned back to Postman, you can see the actual content is blank:
{
"Version": {
"Major": 1,
"Minor": 1,
"Build": -1,
"Revision": -1,
"MajorRevision": -1,
"MinorRevision": -1
},
"Content": {
"Headers": [
{
"Key": "Content-Type",
"Value": ["text/plain; charset=utf-8"]
}]
},
"StatusCode": 200,
"ReasonPhrase": "OK",
"Headers": [],
"RequestMessage": null,
"IsSuccessStatusCode": true
}
That was the pretty version. Here is what the response looks like raw. {"Version":"Major":1,"Minor":1,"Build":-1,"Revision":-1,"MajorRevision":-1,"MinorRevision":-1},"Content":{"Headers":[{"Key":"Content-Type","Value":["text/xml; charset=utf-8"]}]},"StatusCode":200,"ReasonPhrase":"OK","Headers":[],"RequestMessage":null,"IsSuccessStatusCode":true}
Another example of just a very plain vanilla post response:
:(
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using System.Text;
using MyNamespace.Models;
namespace MyNamespace.Controllers
{
[Route("[controller]")]
public class BasicTextResponseController : Controller
{
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// POST api/values
[HttpPost]
public HttpResponseMessage Post(TwilioCall call)
{
var responseMessage = new HttpResponseMessage
{
Content = new StringContent("Text to return.")
};
return responseMessage;
}
}
}