I am developing a Web API service on ASP.NET (C#).
[HttpPost, Route("add_role")]
public async Task<HttpResponseMessage> addRole(string roleName, string roleDescription)
{
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent("some string", Encoding.UTF8, "text/html"),
};
return response;
}
And that’s what I can see in postman
{
"version": "1.1",
"content": {
"headers": [
{
"key": "Content-Type",
"value": [
"text/html"
]
}
]
},
"statusCode": 200,
"reasonPhrase": "OK",
"headers": [],
"trailingHeaders": [],
"requestMessage": null,
"isSuccessStatusCode": true
}
So I can only see the content type instead of an actual string. How can I fix this?
2
Answers
You should change the content type from
"text/html"
to"text/plain"
.If you want Return a string ,Can use
Change Action "Task" To "Task"
and Use other Return way insted of HttpResponseMessage
Change Return
1.