webapi2返回不带引号的简单字符串 [英] webapi2 return simple string without quotation mark
本文介绍了webapi2返回不带引号的简单字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单情况:
public IHttpActionResult Get()
{
return Ok<string>("I am send by HTTP resonse");
}
返回:
"I am send by HTTP resonse"
很好奇,我可以避免用引号引起来吗?
Just curious, can I avoid the quotation mark in other words return:
I am send by HTTP resonse
或者这在HTTP中是必需的吗?
or is this necessary in HTTP?
推荐答案
是的,您可以避免使用"
Yes you can avoid the "
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>
标记但不带引号的结果:)
The result with <string>
tag but without quotes :)
编辑
如果您不喜欢这种方法,请尝试一下.它只返回文本
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;
}
这篇关于webapi2返回不带引号的简单字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文