C# - 如何正确响应HTTP“GET”请求

时间:2014-07-17 03:57:00

标签: c# html http networking

不知怎的,我相信我没有正确地处理我的HTTP请求。

看看这个标记:

<!DOCTYPE html>
<html>
<body>
    <h1>This is my picture</h1>
    <img border="0" src="Image.jpg" alt="Pulpit rock" width="304" height="228">
</body>
</html>

使用Google Chrome浏览器打开此文档时,可以使用其他浏览器(如Internet Explorer),该页面正常工作,图像也会在页面上呈现。

但是,当我将此文档从我的服务器发送到客户端(另一台运行浏览器的计算机)时,所有标题加载正常但图像未加载。

我收到了请求:&#34; GET /Image.jpg" HTTP / 1.1&#34;

我这样处理:

string Request = StreamReader.ReadLine();
string Page;

if (Request != null)
{
    string[] RequestTokens = Request.Split(' ');
    Page = RequestTokens[1];
}

if(Page == "/Image.jpg")
{
    StreamWriter.WriteLine("HTTP/1.0 200 OK\n");
    byte[] image = File.ReadAllBytes("Image.jpg");
    StreamWriter.Write(image, 0, image.Length);
} 

并且......我尝试发送string和许多类似的东西,但我仍然无法看到浏览器上的图像!!!

请回答...... 谢谢......

0 个答案:

没有答案
相关问题