自己写个IIS玩-协议解析篇
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-05-20
//todo:壙扮音深打謹倖揖兆議遊 Headers[line.String1] = line.String2; if (Headers.ContainsKey(CONTENT_LENGTH_HEADER)) ContentLength = int.Parse(Headers [CONTENT_LENGTH_HEADER].Trim()); } #endregion } } internal HttpRequest AsRequest() { if (MessageType != MessageType.Request) throw new ApplicationException("this message is not request"); HttpRequest request = new HttpRequest(this); string[] tempArr = startLine.Split('' ''); if (tempArr.Length != 3) throw new ApplicationException("start line error:" + startLine); request.Method = tempArr[0].Trim(); request.Uri = tempArr[1]; request.Protocol = tempArr[2]; if (!request.Protocol.StartsWith(PROTOCOL)) throw new ApplicationException("Protocol error:" + request.Protocol); return request; } internal HttpResponse AsResponse() { if (MessageType != MessageType.Response) throw new ApplicationException("this message is not response"); HttpResponse response = new HttpResponse(this); string[] tempArr = startLine.Split('' ''); if (tempArr.Length != 3) throw new ApplicationException("start line error:" + startLine); response.Protocol = tempArr[0]; if (!response.Protocol.StartsWith(PROTOCOL)) throw new ApplicationException("Protocol error:" + response.Protocol); response.StatusCode = int.Parse(tempArr[1].Trim()); //todo:辛嬬嗤200.1 宸劔議哘基 response.Desc = tempArr[2]; //todo:音深打哘基宙峰淫根腎鯉議秤趨 return response; } public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append(startLine); sb.AppendLine(); foreach (KeyValuePair<string,string> pair in Headers) { sb.AppendFormat("{0}:{1}", pair.Key, pair.Value); sb.AppendLine(); } sb.AppendLine(); sb.AppendLine(); if (BodyStr != null) sb.Append(Encoding.UTF8.GetString (BodyStr.Bytes)); return sb.ToString(); } } HttpParser?麼勣議亅咏盾裂窃?秘笥頁Parse圭隈?辛參委耽肝socket辺欺議忖准方怏肇距喘乎圭隈 ?隼朔匡堋RequestReceived?ResponseReceived?Error吉圭隈。醤 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于自己写个IIS玩-协议解析篇的所有评论