当前位置: 首页 > news >正文

有什么网站是做企业型的网络营销方案案例范文

有什么网站是做企业型的,网络营销方案案例范文,怎么设计网络营销方案,关于网站备案的公告使用C#和Socket从头实现的带有文件上传和下载功能的HTTP服务器。它支持GET、POST请求方法,并能处理URL参数、请求体以及文件上传和下载。 using System; using System.IO; using System.Net; using System.Net.Sockets; using System.Text;class HttpServer {publi…

使用C#和Socket从头实现的带有文件上传和下载功能的HTTP服务器。它支持GET、POST请求方法,并能处理URL参数、请求体以及文件上传和下载。

using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;class HttpServer
{public static void Main(string[] args){const int port = 8080;TcpListener listener = new TcpListener(IPAddress.Any, port);listener.Start();Console.WriteLine("HTTP server is running on port {0}...", port);while (true){TcpClient client = listener.AcceptTcpClient();ProcessClientRequest(client);}}public static void ProcessClientRequest(TcpClient client){using (NetworkStream stream = client.GetStream()){// 读取请求数据byte[] buffer = new byte[4096];int bytesRead = stream.Read(buffer, 0, buffer.Length);string requestString = Encoding.UTF8.GetString(buffer, 0, bytesRead);// 解析请求HttpRequest request = ParseRequest(requestString);// 构造响应数据HttpResponse response = BuildResponse(request);// 发送响应头byte[] responseHeaderBytes = Encoding.UTF8.GetBytes(response.GetHeaderString());stream.Write(responseHeaderBytes, 0, responseHeaderBytes.Length);// 发送响应体(如果有)if (response.ContentStream != null){byte[] bufferBytes = new byte[4096];int bytesToRead;while ((bytesToRead = response.ContentStream.Read(bufferBytes, 0, bufferBytes.Length)) > 0){stream.Write(bufferBytes, 0, bytesToRead);}response.ContentStream.Close();}}client.Close();}public static HttpRequest ParseRequest(string requestString){var request = new HttpRequest();string[] lines = requestString.Split(new[] { "\r\n" }, StringSplitOptions.None);// 解析请求行string[] requestLineParts = lines[0].Split(' ');request.Method = requestLineParts[0].ToUpper();request.Path = requestLineParts[1];// 解析请求头for (int i = 1; i < lines.Length; i++){string[] headerParts = lines[i].Split(':');if (headerParts.Length == 2){string key = headerParts[0].Trim();string value = headerParts[1].Trim();request.Headers[key] = value;}}// 解析请求体(仅对POST请求处理)if (request.Method == "POST"){int bodyIndex = Array.IndexOf(lines, "");if (bodyIndex != -1 && bodyIndex < lines.Length - 1){request.Body = lines[bodyIndex + 1];}}return request;}public static HttpResponse BuildResponse(HttpRequest request){var response = new HttpResponse();// 设置响应头信息response.StatusCode = 200;response.StatusDescription = "OK";response.Headers["Content-Type"] = "text/plain; charset=utf-8";// 处理文件上传if (request.Method == "POST" && request.Headers.ContainsKey("Content-Disposition")){string filename = GetFilenameFromContentDisposition(request.Headers["Content-Disposition"]);using (FileStream fileStream = File.Create(filename)){using (StreamWriter writer = new StreamWriter(fileStream)){writer.Write(request.Body);}}response.SetContent("File uploaded successfully.");}// 处理文件下载else if (request.Method == "GET" && request.Path.StartsWith("/download/")){string filepath = request.Path.Substring("/download/".Length);if (File.Exists(filepath)){response.StatusCode = 200;response.StatusDescription = "OK";response.Headers["Content-Type"] = "application/octet-stream";response.Headers["Content-Disposition"] = $"attachment; filename=\"{Path.GetFileName(filepath)}\"";response.ContentStream = File.OpenRead(filepath);}else{response.StatusCode = 404;response.StatusDescription = "Not Found";response.SetContent("File not found.");}}// 默认返回文本内容else{string content = "Welcome to the HTTP server.";response.SetContent(content);}return response;}public static string GetFilenameFromContentDisposition(string contentDisposition){const string keyword = "filename=\"";int startIndex = contentDisposition.IndexOf(keyword) + keyword.Length;int endIndex = contentDisposition.IndexOf("\"", startIndex);return contentDisposition.Substring(startIndex, endIndex - startIndex);}
}class HttpRequest
{public string Method { get; set; }public string Path { get; set; }public IDictionary<string, string> Headers { get; set; } = new Dictionary<string, string>();public string Body { get; set; }
}class HttpResponse
{public int StatusCode { get; set; }public string StatusDescription { get; set; }public IDictionary<string, string> Headers { get; set; } = new Dictionary<string, string>();public Stream ContentStream { get; set; }public void SetContent(string content){byte[] contentBytes = Encoding.UTF8.GetBytes(content);ContentStream = new MemoryStream(contentBytes);Headers["Content-Length"] = contentBytes.Length.ToString();}public string GetHeaderString(){StringBuilder builder = new StringBuilder();builder.AppendFormat("HTTP/1.1 {0} {1}\r\n", StatusCode, StatusDescription);foreach (var header in Headers){builder.AppendFormat("{0}: {1}\r\n", header.Key, header.Value);}builder.Append("\r\n");return builder.ToString();}
}

http://www.hrbkazy.com/news/49007.html

相关文章:

  • 杭州免费网站建站模板推广赚钱的微信小程序
  • 哪个网站免费做简历网站点击快速排名
  • 温州网站优化百度业务范围
  • web网站开发+语言西安seo顾问公司
  • 免费创建网站平台有哪些域名交易
  • 网站设计背景图片如何做网站网页
  • 网站营销方案模板百度推广费用可以退吗
  • 手机网站建设模板下载南宁网站建设网络公司
  • 百度网站名称网站运营策划书
  • 邯郸建网站企业培训机构排名前十
  • 我们做的网站是优化型结构关键词排名是什么意思
  • 科技网站配色方案软文案例大全
  • 如何做网站外链优化搜索引擎
  • 深圳营业执照代办seo高级教程
  • 苏州网站排名爱站在线关键词挖掘
  • 潍坊网站建设电话西安seo排名扣费
  • 数据库做网站中央下令全国各地核酸检测
  • 两个域名 两个网站 如何推广自己做的网址如何推广
  • wordpress主题编辑seo流量工具
  • 做公司网站怎么做贴吧推广400一个月
  • 网站推广策划思路与执行重庆百度推广电话
  • wordpress自定义文章添加标签百度seo优化系统
  • 签订网站制作合同注意事项谷歌seo优化中文章
  • 淘宝网站模板是什么做的网络平台怎么推广
  • 深圳做网站好的公司网络营销方式包括哪些
  • 西安关键词优化平台关键词seo排名优化软件
  • 在pc端预览手机网站热点事件营销案例
  • 重庆公共交通最新消息网站seo培训
  • 如何做免费的公司网站聊城优化seo
  • 调教亲妹妹做性奴网站电商seo搜索优化