简单场景:
public IHttpActionResult Get()
{
return Ok<string>("I am send by HTTP resonse");
}
returns:
"I am send by HTTP resonse"
只是好奇,我可以避免引号,换句话说,返回:
I am send by HTTP resonse
或者这在 HTTP 中是必要的吗?
是的,您可以避免“
public class ValuesController : ApiController
{
public string Get()
{
return "qwerty";
}
}
现在检查http://localhost:3848/api/values
和回应
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">qwerty</string>
结果与<string>
标签但不带引号:)
EDIT
如果你不喜欢这种方法,试试这个。它只返回文本
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)