I have a pretty basic ScriptMethod
:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void GetData(string token)
{
Context.Response.ContentType = "text/json";
Context.Response.Clear();
Context.Response.BufferOutput = true;
List<string> data = new List<string>() { "foo", "bar", "foobar" };
using (var stream = new StreamWriter(Context.Response.OutputStream))
{
JsonSerializer.Create().Serialize(stream, data);
}
Context.Response.OutputStream.Flush();
}
If I hit this API via a GET, I receive an acceptable response:
["foo","bar","foobar"]
If I hit this API via a POST, instead, I receive a malformed response:
["foo","bar","foobar"]{"d":null}
How can I make this function write the response, without appending the d
object?