Я создал C# HttpListener ().
В обработчике запросов я выполняю необходимое, а затем устанавливаю заголовки и тип MIME для объекта ответа. Однако браузер сообщил, что тип MIME всегда был пустым.
private void HandleWebRequest(HttpListenerContext context)
{
string path = context.Request.Url.LocalPath.ToLowerInvariant();
HttpListenerResponse response = context.Response;
HttpListenerRequest request = context.Request;
try
{
// Respond to requests here. For ex:
byte[] displayImage = HtmlHelper.GetTextResource(path.Substring(20));
response.ContentLength64 = displayImage.Length;
response.OutputStream.Write(displayImage, 0, displayImage.Length);
}
finally
{
SetResponseHeaders(path, response);
response.Close();
}
}
private void SetResponseHeaders(path, response)
{
...
response.ContentType = MediaTypeNames.Text.Plain;
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
response.AddHeader("Access-Control-Allow-Methods", "GET,POST");
response.AddHeader("Access-Control-Allow-Origin", "*");
}