Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让我的服务器(AWS EC2)以C#中的html格式发送.html文件?_C#_Html_Amazon Web Services_Amazon Ec2_Server - Fatal编程技术网

如何让我的服务器(AWS EC2)以C#中的html格式发送.html文件?

如何让我的服务器(AWS EC2)以C#中的html格式发送.html文件?,c#,html,amazon-web-services,amazon-ec2,server,C#,Html,Amazon Web Services,Amazon Ec2,Server,我使用AmazonWebService的EC2虚拟机设置了一个服务器 我用C#编写的服务器应用程序 目前,我的游戏是用JavaScript编写的,在为highscore板请求数据时,可以向服务器发送数据并接收JSON对象。这一切都很顺利 我决定尝试从服务器上托管我的游戏。但是由于某种原因,如果您请求index.html文件,客户端浏览器解释的是原始文本。正如您在这里看到的(),它将index.html文件显示为文本,并将其放在客户机主体中的“pre”标记下 我最初认为这是一个安全问题,但我在EC

我使用AmazonWebService的EC2虚拟机设置了一个服务器

我用C#编写的服务器应用程序

目前,我的游戏是用JavaScript编写的,在为highscore板请求数据时,可以向服务器发送数据并接收JSON对象。这一切都很顺利

我决定尝试从服务器上托管我的游戏。但是由于某种原因,如果您请求index.html文件,客户端浏览器解释的是原始文本。正如您在这里看到的(),它将index.html文件显示为文本,并将其放在客户机主体中的“pre”标记下

我最初认为这是一个安全问题,但我在EC2实例的安全性中找不到任何不允许它的东西。另外,当我通过VisualStudio使用localhost:8080托管它时,我有同样的东西,这让我相信它在我的代码中

另外,值得一提的是,我检查了我的regedit,并确保所有.html内容都是“text/html”类型

在C#中,在确定用户试图请求什么之后(我知道这是可行的,因为它确实获取了正确的html文件),它调用以下方法

private static Response IndexRequest()
    {
        String file = "C:\\Game\\index.html";
        FileInfo fi = new FileInfo(file);
        FileStream fs = fi.OpenRead();
        BinaryReader reader = new BinaryReader(fs);
        Byte[] d = new Byte[fs.Length];
        reader.Read(d, 0, d.Length);
        fs.Close();

        return new Response("Play", "text/html", d);
    }
该方法实质上读取index.html文件并将其更改为字节数组以进行发送,然后返回一个状态为Play的对象,类型为“text/html”,其中包含该数组

调用该方法的对象使用该数据接收对象响应。然后,该对象响应被告知调用其post方法,如下所示

public void Post(NetworkStream stream) {
        StreamWriter writer = new StreamWriter(stream);
        writer.WriteLine(String.Format("{0} {1}\r\nServer: {2}\r\nContent-Type: {3}\r\nAccept-Ranges: bytes\r\nContent-Length: {4}\r\n",
            HTTPServer.VERSION, status, HTTPServer.NAME, mime, data.Length));

        stream.Write(data, 0, data.Length);
    }
在哪里 HTTPServer.VERSION==“HTTP/1.1”, HTTPServer.NAME=“HarbourGuide HTTP服务器V0.1” status/mime/data是作为参数从第一个方法返回的三个内容(在本例中为“Play”、“text/html”、index.html的数据作为bbyte数组

正如我所说,这会导致客户端以文本的形式接收数据。将mime更改为“html”不起作用

任何帮助都将不胜感激。谢谢