Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webapi2 return simple string without quotation mark

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?

like image 440
cs0815 Avatar asked Nov 13 '15 08:11

cs0815


People also ask

How do you escape quotation marks in a string?

' You can put a backslash character followed by a quote ( \" or \' ). This is called an escape sequence and Python will remove the backslash, and put just the quote in the string.

Do string variables need quotation marks?

String values must be enclosed in single or double quote marks. For variables such as [$END_USER$ sting values enclosed in double quote marks are resolved, whereas those enclosed in single quote marks are kept as-is.

How do you put quotation marks in a string C++?

To place quotation marks in a string in your code In Visual C# and Visual C++, insert the escape sequence \" as an embedded quotation mark.


1 Answers

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;
}
like image 116
slava Avatar answered Sep 28 '22 09:09

slava