我有一个用C#编写的小型HTTP服务器,到目前为止,我只需要向发送者发送原始文本。但现在我需要发送一张JPG图片,我不知道该怎么做。
这是我现在拥有的:
// Read the HTTP Request
Byte[] bReceive = new Byte[MAXBUFFERSIZE];
int i = socket.Receive(bReceive, bReceive.Length, 0);
//Convert Byte to String
string sBuffer = Encoding.ASCII.GetString(bReceive);
// Look for HTTP request
iStartPos = sBuffer.IndexOf("HTTP", 1);
// Extract the Command without GET_/ at the beginning and _HTTP at the end
sRequest = sBuffer.Substring(5, iStartPos - 1 - 5);
String answer = handleRequest(sRequest);
// Send the response
socket.Send(Encoding.UTF8.GetBytes(answer));
我想我需要使用文件流而不是字符串,但我真的一点头绪都没有..