{"id":514,"date":"2023-05-24T15:50:48","date_gmt":"2023-05-24T07:50:48","guid":{"rendered":"https:\/\/app.60day.cn\/appday\/?p=514"},"modified":"2023-05-24T15:50:48","modified_gmt":"2023-05-24T07:50:48","slug":"exe%e5%88%9b%e5%bb%bahttp%e6%9c%8d%e5%8a%a1%e6%b3%a8%e6%84%8f%e7%82%b9%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/app.60day.cn\/appday\/kaifaexe\/514\/","title":{"rendered":"exe\u521b\u5efahttp\u670d\u52a1\u6ce8\u610f\u70b9\u662f\u4ec0\u4e48?"},"content":{"rendered":"<p>EXE \u521b\u5efa HTTP \u670d\u52a1\uff0c\u662f\u6307\u5c06\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff08EXE\uff09\u8f6c\u5316\u4e3a\u4e00\u4e2a HTTP \u670d\u52a1\uff0c\u8ba9\u5176\u4ed6\u8ba1\u7b97\u673a\u53ef\u4ee5\u901a\u8fc7 HTTP \u534f\u8bae\u8bbf\u95ee\u8be5\u670d\u52a1\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u5c06\u4e00\u4e2a\u8ba1\u7b97\u673a\u4e0a\u7684\u5e94\u7528\u7a0b\u5e8f\u6216\u670d\u52a1\u5feb\u901f\u5730\u53d1\u5e03\u5230\u5176\u4ed6\u8ba1\u7b97\u673a\u4e0a\uff0c\u4fbf\u4e8e\u8fdc\u7a0b\u8bbf\u95ee\u548c\u7ba1\u7406\u3002\u4e0b\u9762\u5c31\u6765\u8be6\u7ec6\u4ecb\u7ecd\u4e00\u4e0b EXE \u521b\u5efa HTTP \u670d\u52a1\u7684\u539f\u7406\u548c\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n<p>\u4e00\u3001\u539f\u7406<\/p>\n<p>EXE \u521b\u5efa HTTP \u670d\u52a1\u7684\u57fa\u672c\u539f\u7406\u662f\u901a\u8fc7\u5c06\u53ef\u6267\u884c\u6587\u4ef6\u8f6c\u5316\u4e3a HTTP \u670d\u52a1\uff0c\u8ba9\u5176\u4ed6\u8ba1\u7b97\u673a\u53ef\u4ee5<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/15\/11\/09745119245.jpg\" \/><\/figure>\n<\/p>\n<p>\u901a\u8fc7 HTTP \u534f\u8bae\u8bbf\u95ee\u8be5\u670d\u52a1\u3002\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p>1. \u5c06\u53ef\u6267\u884c\u6587\u4ef6\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u76d1\u542c Socket\u3002<\/p>\n<p>2. \u4f7f\u7528 HTTP \u534f\u8bae\u76d1\u542c Socket\uff0c\u5e76\u5c06\u8bf7\u6c42\u8f6c\u53d1\u7ed9\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p>3. \u53ef\u6267\u884c\u6587\u4ef6\u63a5\u6536\u8bf7\u6c42\uff0c\u5904\u7406\u8bf7\u6c42\uff0c\u5e76\u5c06\u7ed3\u679c\u8fd4\u56de\u7ed9 HTTP \u670d\u52a1\u3002<\/p>\n<p>4. HTTP \u670d\u52a1\u5c06\u7ed3\u679c\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p>\u4e8c\u3001\u5b9e\u73b0\u65b9\u6cd5<\/p>\n<p>EXE \u521b\u5efa HTTP \u670d\u52a1\u7684\u5b9e\u73b0\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5982\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3001\u7f16\u5199\u81ea\u5df1\u7684 HTTP \u670d\u52a1\u5668\u7b49\u3002\u4e0b\u9762\u4ecb\u7ecd\u4e24\u79cd\u5e38\u7528\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n<p>1. \u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/p>\n<p>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u53ef\u4ee5\u7b80\u5316\u4ee3\u7801\u7f16\u5199\u8fc7\u7a0b\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u5e38\u7528\u7684\u7b2c\u4e09\u65b9\u5e93\u6709 HttpListener\u3001Nancy \u7b49\u3002<\/p>\n<p>\u4ee5 HttpListener \u4e3a\u4f8b\uff0c\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>&#8220;`csharp<\/p>\n<p>using System;<\/p>\n<p>using System.Net;<\/p>\n<p>using System.Threading;<\/p>\n<p>class Program<\/p>\n<p>{<\/p>\n<p>    static void Main(string[] args)<\/p>\n<p>    {<\/p>\n<p>        HttpListener listener = new HttpListener();<\/p>\n<p>        lis<a href=\"https:\/\/exe.yimenapp.com\/tool-322.html\">\u5236\u4f5cexe\u7a0b\u5e8f\u7684\u8f6f\u4ef6<\/a>tener.Prefixes.Add(&#8220;http:\/\/localhost:8080\/&#8221;);<\/p>\n<p>        listener.Start();<\/p>\n<p>        Console.WriteLine(&#8220;Listening&#8230;&#8221;);<\/p>\n<p>        while (true)<\/p>\n<p>        {<\/p>\n<p>            HttpListenerContext context = listener.GetContext();<\/p>\n<p>            ThreadPool.QueueUserWorkItem((o) =&gt;<\/p>\n<p>            {<\/p>\n<p>                HttpListenerResponse response = context.Response;<\/p>\n<p>                response.ContentType = &#8220;text\/plain&#8221;;<\/p>\n<p>                string responseString = &#8220;Hello World!&#8221;;<\/p>\n<p>                byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);<\/p>\n<p>                response.ContentLength64 = buffer.Length;<\/p>\n<p>                System.IO.Stream output = response.OutputStream;<\/p>\n<p>                output.Write(buffer, 0, buffer.Length);<\/p>\n<p>                output.Close();<\/p>\n<p>            });<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>2. \u7f16\u5199\u81ea\u5df1\u7684 HTTP \u670d\u52a1\u5668<\/p>\n<p>\u7f16\u5199\u81ea\u5df1\u7684 HTTP \u670d\u52a1\u5668\u53ef\u4ee5\u66f4\u597d\u5730\u638c\u63e1\u5b9e\u73b0\u539f\u7406\uff0c\u4f46\u9700\u8981\u7f16\u5199\u66f4\u591a\u7684\u4ee3\u7801\u3002\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>&#8220;`csharp<\/p>\n<p>using System;<\/p>\n<p>using System.Net;<\/p>\n<p>using System.Net.Sockets;<\/p>\n<p>using System.Text;<\/p>\n<p>class Program<\/p>\n<p>{<\/p>\n<p>    static void Main(string[] args)<\/p>\n<p>    {<\/p>\n<p>        TcpListener listener = new TcpListener(IPAddress.Any, 8080);<\/p>\n<p>        listener.Start()<a href=\"https:\/\/exe.yimenapp.com\/tool-855.html\">mac\u5f00\u53d1\u8bfe\u7a0b<\/a>;<\/p>\n<p>        Console.WriteLine(&#8220;Listening&#8230;&#8221;);<\/p>\n<p>        while (true)<\/p>\n<p>        {<\/p>\n<p>            TcpClient client = listener.AcceptTcpClient();<\/p>\n<p>            Console.WriteLine(&#8220;Accepted connection from {0}&#8221;, client.Client.RemoteEndPoint);<\/p>\n<p>            NetworkStream stream = client.GetStream();<\/p>\n<p>            byte[] buffer = new byte[1024];<\/p>\n<p>            int bytesRead = stream.Read(buffer, 0, buffer.Length);<\/p>\n<p>            string request = Encoding.ASCII.GetString(buffer, 0, bytesRead);<\/p>\n<p>            Console.WriteLine(&#8220;Received request:\\n{0}&#8221;, request);<\/p>\n<p>            string response = &#8220;HTTP\/1.1 200 OK\\nContent-Type: text\/plain\\nContent-Length: 12\\n\\nHello World!&#8221;;<\/p>\n<p>            byte[] responseBytes = Encoding.ASCII.GetBytes(response);<\/p>\n<p>            stream.Write(responseBytes, 0, responseBytes.Length);<\/p>\n<p>            Console.WriteLine(&#8220;Sent response:\\n{0}&#8221;, response);<\/p>\n<p>            client.Close();<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u4ee5\u4e0a\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u5b9e\u73b0\u5c06\u53ef\u6267\u884c\u6587\u4ef6\u8f6c\u5316\u4e3a HTTP \u670d\u52a1\uff0c\u8ba9\u5176\u4ed6\u8ba1\u7b97\u673a\u53ef\u4ee5\u901a\u8fc7 HTTP \u534f\u8bae\u8bbf\u95ee\u8be5\u670d\u52a1\u3002\u5177\u4f53\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u548c\u5f00\u53d1\u7ecf\u9a8c\u6765\u51b3\u5b9a\u3002<\/p>\n<p>\u4e09\u3001\u603b\u7ed3<\/p>\n<p>EXE \u521b\u5efa HTTP \u670d\u52a1\u662f\u4e00\u79cd\u5feb\u901f\u53d1\u5e03\u5e94\u7528\u7a0b\u5e8f\u6216\u670d\u52a1\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u8ba9\u5176\u4ed6\u8ba1\u7b97\u673a\u901a\u8fc7 HTTP \u534f\u8bae\u8bbf\u95ee\u8be5\u670d\u52a1\u3002\u5b9e\u73b0\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u6216\u7f16\u5199\u81ea\u5df1\u7684 HTTP \u670d\u52a1\u5668\u3002\u65e0\u8bba\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u9700\u8981\u638c\u63e1 HTTP \u534f\u8bae\u548c Socket \u7f16\u7a0b\u77e5\u8bc6\uff0c\u624d\u80fd\u66f4\u597d\u5730\u7406\u89e3\u548c\u5b9e\u73b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>EXE \u521b\u5efa HTTP \u670d\u52a1\uff0c\u662f\u6307\u5c06\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff08EXE\uff09\u8f6c\u5316\u4e3a\u4e00\u4e2a HTTP \u670d\u52a1\uff0c\u8ba9\u5176\u4ed6\u8ba1\u7b97\u673a\u53ef\u4ee5\u901a\u8fc7 HTTP \u534f\u8bae\u8bbf\u95ee\u8be5\u670d\u52a1\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u5c06\u4e00\u4e2a\u8ba1\u7b97\u673a\u4e0a\u7684\u5e94\u7528\u7a0b\u5e8f\u6216\u670d\u52a1\u5feb\u901f\u5730\u53d1\u5e03\u5230\u5176\u4ed6\u8ba1\u7b97<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[1227,1226,431,195,207],"topic":[],"class_list":{"0":"post-514","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-kaifaexe","7":"tag-windows","9":"tag-431","10":"tag-195","11":"tag-207"},"_links":{"self":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/comments?post=514"}],"version-history":[{"count":0,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/514\/revisions"}],"wp:attachment":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/media?parent=514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/categories?post=514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/tags?post=514"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/topic?post=514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}