我正在编写一个网络服务器和一个客户端,通过端口43上的本地主机使用http 0.9进行相互连接,但是当我发送一个诸如-h9(以检测协议)的请求时,你好(第一个争论) (响应第一个争论的位置)它只收到一小部分代码,这些代码变成只有“你好”的部分而不是“你好,所有人”,因为它应该通过。 以下是我的客户代码
case "-h9":// http/0.9 protocol
if (args.Length == 3)
{
whatIsSent = "PUT /" + args[1] + "\r\n\r\n" + args[2] ;
//sw.Write(whatIsSent);
//sw.Flush();
//not sending all of this on sending put /cssbct
}
else
{
arguments = arguments.Remove(0, 4);
whatIsSent = "GET /" + arguments;
//sw.Write(whatIsSent);
}
break;
这是来自服务器
while (connection.Connected)
{
data = sr.ReadLine();//not reading all for PUT/
#region http0.9
if (data.Contains("GET /"))
{
protocol = data.Substring(0, data.IndexOf(" "));
data = data.Substring(1 + (protocol.Length + 1));
switch (protocol)
{
case "GET"://wont work cause of PUT
if (data.Contains(" "))
{
firstArg = data.Substring(0, data.IndexOf(" "));
secondArg = data.Substring(data.IndexOf(" ") + 1, data.Length - firstArg.Length - 1);
useDictionary(firstArg, secondArg, ref returnData);
}
else
{
firstArg = data.Substring(0, data.Length);
secondArg = null;
useDictionary(firstArg, secondArg, ref returnData);
returnData = "HTTP/0.9 200 OK\r\nContent-Type: text/plain\r\n\r\n" + returnData;
}
break;