问题
Simple scenario:
public IHttpActionResult Get()
{
return Ok<string>("I am send by HTTP resonse");
}
returns:
"I am send by HTTP resonse"
Just curious, can I avoid the quotation mark in other words return:
I am send by HTTP resonse
or is this necessary in HTTP?
回答1:
Yes you can avoid the "
public class ValuesController : ApiController
{
public string Get()
{
return "qwerty";
}
}
now check http://localhost:3848/api/values
and response
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">qwerty</string>
The result with <string>
tag but without quotes :)
EDIT
If you don't like this approach,try this.It returns just text
public HttpResponseMessage Get()
{
string result = "Your text";
var resp = new HttpResponseMessage(HttpStatusCode.OK);
resp.Content = new StringContent(result, System.Text.Encoding.UTF8, "text/plain");
return resp;
}
来源:https://stackoverflow.com/questions/33688208/webapi2-return-simple-string-without-quotation-mark