国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Unity中使用HttpListener創(chuàng)建本地Http web服務(wù)器教程與完整代碼

這篇具有很好參考價(jià)值的文章主要介紹了Unity中使用HttpListener創(chuàng)建本地Http web服務(wù)器教程與完整代碼。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

前言

下方有完整代碼和使用方法,急用的請(qǐng)直接拉到最下方

本文可以實(shí)現(xiàn)不開新進(jìn)程在Unity中創(chuàng)建http服務(wù)器。
監(jiān)聽自定義ip獲取指定目錄下的網(wǎng)頁(yè)或其他資源。如果網(wǎng)頁(yè)內(nèi)有其他資源鏈接也可以正常訪問(wèn)。
可以配合Unity網(wǎng)頁(yè)瀏覽器組件使用解決資源打包問(wèn)題

在Unity中搭建簡(jiǎn)易http服務(wù)主要分為三步

  1. 監(jiān)聽訪問(wèn)請(qǐng)求
  2. 解析請(qǐng)求
  3. 響應(yīng)請(qǐng)求

1 監(jiān)聽訪問(wèn)請(qǐng)求

監(jiān)聽服務(wù)使用的是System.Net庫(kù)中的HttpListener組件,并使用其Start()方法對(duì)相關(guān)端口的訪問(wèn)進(jìn)行監(jiān)聽

using System;
using System.Net;
public class HttpServer : MonoBehaviour
{
    // 服務(wù)器對(duì)象
    private  HttpListener listener;
    // 要監(jiān)聽的目標(biāo)地址
    private string localIp = "http://localhost:8081/";
    // 本地web資源地址
    private string localFilePath = "C:\\Users\\Desktop\\html";
}

一般執(zhí)行監(jiān)聽有三種方式:
第一種就是用whilet(true)循環(huán)監(jiān)聽, 這種方式會(huì)阻塞當(dāng)前線程。
第二種是調(diào)用threadingpool線程池開一個(gè)線程監(jiān)聽請(qǐng)求,是比較常用的方式
第三種是使用異步監(jiān)聽。本文使用的是第三種

listener.BeginGetContext(Response, null);

listener.BeginGetContext會(huì)開啟異步監(jiān)聽,監(jiān)聽到訪問(wèn)會(huì)回調(diào)我們自定義的Response方法并傳入請(qǐng)求信息,我們對(duì)訪問(wèn)請(qǐng)求的數(shù)據(jù)解析和響應(yīng)都要在這個(gè)方法中完成,并且要在其中再次調(diào)用listener.BeginGetContext方法來(lái)保持持續(xù)監(jiān)聽

    void Start()
    {
        listener = new HttpListener();
        // 定義url
        listener.Prefixes.Add(localIp);
        listener.Start();
        // 使用異步監(jiān)聽Web請(qǐng)求,當(dāng)客戶端的網(wǎng)絡(luò)請(qǐng)求到來(lái)時(shí)會(huì)自動(dòng)執(zhí)行委托
        listener.BeginGetContext(Response, null);
        // 提示信息
        Debug.Log($"服務(wù)已啟動(dòng) {DateTime.Now.ToString()},訪問(wèn)地址:{localIp}");
    }
    private void Response(IAsyncResult ar)
	{
    	// 再次開啟異步監(jiān)聽
    	listener.BeginGetContext(Response, null);
    }

2 解析請(qǐng)求

解析請(qǐng)求的目的是根據(jù)訪問(wèn)地址來(lái)定位文件資源的目錄和區(qū)分文件不同類型的處理辦法。
比如訪問(wèn)的地址是www.baidu.com/folder/index.html,我們首先要得到/folder/index.html這個(gè)文件相對(duì)地址來(lái)定位這個(gè)文件在本地磁盤上的路徑,然后得到html這個(gè)文件的擴(kuò)展名,來(lái)對(duì)html文件的處理方式做專門的說(shuō)明

var context = listener.EndGetContext(ar)用來(lái)獲取傳入的請(qǐng)求數(shù)據(jù)
var request = context.Request; 用來(lái)獲取請(qǐng)求信息

private void Response(IAsyncResult ar)
{
    // 再次開啟異步監(jiān)聽
    listener.BeginGetContext(Response, null);
    Debug.Log($"{DateTime.Now.ToString()}接到新的請(qǐng)求");

    // 獲取context對(duì)象
    var context = listener.EndGetContext(ar);
    // 獲取請(qǐng)求體
    var request = context.Request;
    
    // 配置響應(yīng)結(jié)構(gòu)
    try
    {
        // 獲取網(wǎng)址中指定的文件名,比如www.baidu.com/show.html, 這里會(huì)得到show.如果為空就默認(rèn)為index.html
        string filename = context.Request.Url.AbsolutePath.Trim('/');
        if (filename == "")
        {
            filename = "index.html";
        }

        // 獲取文件擴(kuò)展名,比如file.jpg,這里拿到的就是jpg
        string[] ext_list = filename.Split('.');
        string ext = ext_list.Length > 1? ext_list[ext_list.Length - 1]:"";
    }
}

3 響應(yīng)請(qǐng)求

響應(yīng)請(qǐng)求要做的是,組織好要提供給訪問(wèn)者的資源,然后指明該資源在瀏覽器中應(yīng)該怎樣呈現(xiàn)
在這一部分中,

我們首先根據(jù)解析出來(lái)的文件相對(duì)路徑與設(shè)置好的本地資源目錄來(lái)獲得目標(biāo)資源的絕對(duì)路徑:string absPath = Path.Combine(localFilePath, filename);

然后為html擴(kuò)展名的文件設(shè)置響應(yīng)頭信息,讓他以網(wǎng)頁(yè)的形式在瀏覽器中正常展示:switch (ext){ case “html”: context.Response.ContentType = “text/html”;

接著將文件數(shù)據(jù)轉(zhuǎn)為數(shù)據(jù) msg = File.ReadAllBytes(absPath);context.Response.ContentLength64 = msg.Length;

最后將數(shù)據(jù)發(fā)給客戶端 using (Stream s = context.Response.OutputStream) { s.Write(msg, 0, msg.Length); }

 private void Response(IAsyncResult ar)
 {
         // 獲取網(wǎng)址中指定的文件名,比如www.baidu.com/show.html, 這里會(huì)得到show.如果為空就默認(rèn)為index.html
         string filename = context.Request.Url.AbsolutePath.Trim('/');
         if (filename == "")
         {
             filename = "index.html";
         }

         // 獲取文件擴(kuò)展名,比如file.jpg,這里拿到的就是jpg
         string[] ext_list = filename.Split('.');
         string ext = ext_list.Length > 1? ext_list[ext_list.Length - 1]:"";
         // 根據(jù)結(jié)合本地資源目錄和網(wǎng)址中的文件地址,得到要訪問(wèn)的文件的絕對(duì)路徑
         string absPath = Path.Combine(localFilePath, filename);
         
         // 設(shè)置響應(yīng)狀態(tài),就是網(wǎng)頁(yè)響應(yīng)碼。ok == 200
         context.Response.StatusCode = (int)HttpStatusCode.OK;
         string expires = DateTime.Now.AddYears(10).ToString("r");

         // 根據(jù)文件擴(kuò)展名配置不同的網(wǎng)頁(yè)響應(yīng)頭
         switch (ext)
         {
             case "html":
             case "htm":
                 context.Response.ContentType = "text/html";
                 break;
             case "js":
                 context.Response.ContentType = "application/x-javascript";
                 context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                 context.Response.AddHeader("expires", expires);
                 break;
             case "css":
                 context.Response.ContentType = "text/css";
                 context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                 context.Response.AddHeader("expires", expires);
                 break;
             case "jpg":
             case "jpeg":
             case "jpe":
                 context.Response.ContentType = "image/jpeg";
                 context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                 context.Response.AddHeader("expires", expires);
                 break;
             case "png":
                 context.Response.ContentType = "image/png";
                 context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                 context.Response.AddHeader("expires", expires);
                 break;
             case "gif":
                 context.Response.ContentType = "image/gif";
                 context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                 context.Response.AddHeader("expires", expires);
                 break;
             case "ico":
                 context.Response.ContentType = "application/x-ico";
                 context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                 context.Response.AddHeader("expires", expires);
                 break;
             case "txt":
                 context.Response.ContentType = "text/plain";
                 break;
             case "do":
                 context.Response.AddHeader("Access-Control-Allow-Origin", "*");
                 context.Response.ContentType = "text/plain;charset=utf-8";
                 break;
             default:
                 context.Response.ContentType = "";
                 context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                 context.Response.AddHeader("expires", expires);
                 break;
         }

         // 組織數(shù)據(jù)流
         byte[] msg = new byte[0];
         if (msg.Length == 0)
         {
             // 如果目標(biāo)文件不存在就顯示錯(cuò)誤頁(yè)面
             if (!File.Exists(absPath))
             {
                 context.Response.ContentType = "text/html";
                 context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                 if (File.Exists(localFilePath + "error.html"))
                 {
                     msg = File.ReadAllBytes(localFilePath + "error.html");
                 }
                 else
                 {
                     msg = Encoding.Default.GetBytes("404");
                 }
             }
             // 如果存在就將文件轉(zhuǎn)為byte流
             else
             {
                 msg = File.ReadAllBytes(absPath);
             }
         }
         // 返回字節(jié)流
         context.Response.ContentLength64 = msg.Length;
         using (Stream s = context.Response.OutputStream)
         {
             s.Write(msg, 0, msg.Length);
         }

         msg = new byte[0];
         GC.Collect();
     }
     catch (Exception ex)
     {
     }
 }

最后清空數(shù)據(jù)即可: msg = new byte[0]; GC.Collect();

完整代碼及使用方式

使用方式:

  1. 在Unity中創(chuàng)建cs腳本其名為HttpServer.cs,將下方代碼copy進(jìn)去保存
  2. 修改成想要監(jiān)控的地址:private string localIp = “http://localhost:8081/”;
  3. 修改成允許被訪問(wèn)的本地資源目錄:private string localFilePath = “C:\Users\Desktop\html”;
  4. 在Unity場(chǎng)景中創(chuàng)建GameObject,然后為該對(duì)象添加HttpServer組件
  5. 運(yùn)行Unity
  6. 打開瀏覽器訪問(wèn)http://localhost:8081/

完整代碼:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-781609.html

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Net;
using System.Text;
using System.IO;

public class HttpServer : MonoBehaviour
{
    // 服務(wù)器對(duì)象
    private  HttpListener listener;
    private string localIp = "http://localhost:8081/";
    // 本地web資源地址
    private string localFilePath = "C:\\Users\\Desktop\\html";

    void Start()
    {
        listener = new HttpListener();
        // 定義url
        listener.Prefixes.Add(localIp);
        listener.Start();
        // 使用異步監(jiān)聽Web請(qǐng)求,當(dāng)客戶端的網(wǎng)絡(luò)請(qǐng)求到來(lái)時(shí)會(huì)自動(dòng)執(zhí)行委托
        listener.BeginGetContext(Response, null);
        // 提示信息
        Debug.Log($"服務(wù)已啟動(dòng) {DateTime.Now.ToString()},訪問(wèn)地址:{localIp}");
    }

    /// <summary>
    ///  處理收到的訪問(wèn)請(qǐng)求
    /// </summary>
    /// <param name="ar">包含請(qǐng)求體的參數(shù)</param>
    private void Response(IAsyncResult ar)
    {
        // 再次開啟異步監(jiān)聽
        listener.BeginGetContext(Response, null);
        Debug.Log($"{DateTime.Now.ToString()}接到新的請(qǐng)求");

        // 獲取context對(duì)象
        var context = listener.EndGetContext(ar);
        // 獲取請(qǐng)求體
        var request = context.Request;
        // 獲取響應(yīng)結(jié)構(gòu)
        var response = context.Response;

        try
        {
            // 獲取網(wǎng)址中指定的文件名,比如www.baidu.com/show.html, 這里會(huì)得到show.如果為空就默認(rèn)為index.html
            string filename = context.Request.Url.AbsolutePath.Trim('/');
            if (filename == "")
            {
                filename = "index.html";
            }

            // 獲取文件擴(kuò)展名,比如file.jpg,這里拿到的就是jpg
            string[] ext_list = filename.Split('.');
            string ext = ext_list.Length > 1? ext_list[ext_list.Length - 1]:"";
            // 根據(jù)結(jié)合本地資源目錄和網(wǎng)址中的文件地址,得到要訪問(wèn)的文件的絕對(duì)路徑
            string absPath = Path.Combine(localFilePath, filename);
            
            // 設(shè)置響應(yīng)狀態(tài),就是網(wǎng)頁(yè)響應(yīng)碼。ok == 200
            context.Response.StatusCode = (int)HttpStatusCode.OK;
            string expires = DateTime.Now.AddYears(10).ToString("r");

            // 根據(jù)文件擴(kuò)展名配置不同的網(wǎng)頁(yè)響應(yīng)頭
            switch (ext)
            {
                case "html":
                case "htm":
                    context.Response.ContentType = "text/html";
                    break;
                case "js":
                    context.Response.ContentType = "application/x-javascript";
                    context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                    context.Response.AddHeader("expires", expires);
                    break;
                case "css":
                    context.Response.ContentType = "text/css";
                    context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                    context.Response.AddHeader("expires", expires);
                    break;
                case "jpg":
                case "jpeg":
                case "jpe":
                    context.Response.ContentType = "image/jpeg";
                    context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                    context.Response.AddHeader("expires", expires);
                    break;
                case "png":
                    context.Response.ContentType = "image/png";
                    context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                    context.Response.AddHeader("expires", expires);
                    break;
                case "gif":
                    context.Response.ContentType = "image/gif";
                    context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                    context.Response.AddHeader("expires", expires);
                    break;
                case "ico":
                    context.Response.ContentType = "application/x-ico";
                    context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                    context.Response.AddHeader("expires", expires);
                    break;
                case "txt":
                    context.Response.ContentType = "text/plain";
                    break;
                case "do":
                    context.Response.AddHeader("Access-Control-Allow-Origin", "*");
                    context.Response.ContentType = "text/plain;charset=utf-8";
                    break;
                default:
                    context.Response.ContentType = "";
                    context.Response.AddHeader("cache-control", "max-age=315360000, immutable");
                    context.Response.AddHeader("expires", expires);
                    break;
            }

            // 組織數(shù)據(jù)流
            byte[] msg = new byte[0];
            if (msg.Length == 0)
            {
                // 如果目標(biāo)文件不存在就顯示錯(cuò)誤頁(yè)面
                if (!File.Exists(absPath))
                {
                    context.Response.ContentType = "text/html";
                    context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    if (File.Exists(localFilePath + "error.html"))
                    {
                        msg = File.ReadAllBytes(localFilePath + "error.html");
                    }
                    else
                    {
                        msg = Encoding.Default.GetBytes("404");
                    }
                }
                // 如果存在就將文件轉(zhuǎn)為byte流
                else
                {
                    msg = File.ReadAllBytes(absPath);
                }
            }
            // 返回字節(jié)流
            context.Response.ContentLength64 = msg.Length;
            using (Stream s = context.Response.OutputStream)
            {
                s.Write(msg, 0, msg.Length);
            }

            msg = new byte[0];
            GC.Collect();
        }
        catch (Exception ex)
        {
        }

        // 跨域等設(shè)置
        // context.Response.AppendHeader("Access-Control-Allow-Headers", "ID,PW");
        // context.Response.AppendHeader("Access-Control-Allow-Method", "post");
        // context.Response.AppendHeader("Access-Control-Allow-Origin", "*"); // 允許跨域請(qǐng)求
        // context.Response.ContentType = "text/plain;charset=UTF-8"; // 響應(yīng)類型為UTF-8純文本格式
        // context.Response.AddHeader("Content-type", "text/plain"); // 添加響應(yīng)頭
        // context.Response.ContentEncoding = Encoding.UTF8;
    }

    private void OnDestroy()
    {
        // httpobj.EndGetContext(null);
    }
}

到了這里,關(guān)于Unity中使用HttpListener創(chuàng)建本地Http web服務(wù)器教程與完整代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Unity導(dǎo)出WebGL工程,并部署本地web服務(wù)器

    Unity導(dǎo)出WebGL工程,并部署本地web服務(wù)器

    在Build Settings-PlayerSettings-Other Settings-Rendering 將Color Space 設(shè)置為Gamma 將Lightmap Encoding 設(shè)置為NormalQuality 在Build Settings-PlayerSettings-Publishing Settings 勾選Decompression Fallback 完成配置修改之后,可以直接在Build界面選擇Build And Run,構(gòu)建結(jié)束后會(huì)由Unity自動(dòng)部署,可以正常打開網(wǎng)頁(yè)。 如果

    2023年04月19日
    瀏覽(19)
  • 本地開發(fā) npm 好用的http server、好用的web server、靜態(tài)服務(wù)器

    本地開發(fā) npm 好用的http server、好用的web server、靜態(tài)服務(wù)器

    有時(shí)需要快速啟動(dòng)一個(gè)web 服務(wù)器(http服務(wù)器)來(lái)伺服靜態(tài)網(wǎng)頁(yè),安裝nginx又太繁瑣,那么可以考慮使用npm serve、http-server、webpack-dev-server。 npm 的serve可以提供給http server功能, 如果你想提供 靜態(tài)站點(diǎn) 、 單頁(yè)面應(yīng)用 或者 靜態(tài)文件 甚至羅列文件夾的內(nèi)容服務(wù),那么npm serve 是

    2024年02月14日
    瀏覽(27)
  • http-server使用,啟動(dòng)本地服務(wù)器 & 使用serve包本地啟動(dòng)

    http-server使用,啟動(dòng)本地服務(wù)器 & 使用serve包本地啟動(dòng)

    http-server使用,啟動(dòng)本地服務(wù)器 使用serve包本地啟動(dòng) 直接打開html文件,跨域不渲染圖片 1、簡(jiǎn)介 官網(wǎng):https://github.com/http-party/http-server http-server是一個(gè)簡(jiǎn)單的零配置命令行 http服務(wù)器 。 它足夠強(qiáng)大,足以用于生產(chǎn)用途,但它既簡(jiǎn)單又易于破解,可用于測(cè)試,本地開發(fā)和學(xué)習(xí)。

    2024年02月02日
    瀏覽(30)
  • 使用 Node 創(chuàng)建 Web 服務(wù)器

    使用 Node 創(chuàng)建 Web 服務(wù)器

    Node.js 提供了 http 模塊,http 模塊主要用于搭建 HTTP 服務(wù)端和客戶端,使用 HTTP 服務(wù)器或客戶端功能必須調(diào)用 http 模塊,代碼如下: 以下是演示一個(gè)最基本的 HTTP 服務(wù)器架構(gòu)(使用 8080 端口),創(chuàng)建 server.js 文件,代碼如下所示: 接下來(lái)我們?cè)谠撃夸浵聞?chuàng)建一個(gè) index.html 文件,代

    2024年01月23日
    瀏覽(28)
  • 使用Docker在Linux服務(wù)器本地部署PaddleSpeech Web服務(wù)

    使用Docker在Linux服務(wù)器本地部署PaddleSpeech Web服務(wù)

    1. 從官方Docker Hub拉取環(huán)境 2. 啟動(dòng)容器并分派端口 3. 自然語(yǔ)言處理工具庫(kù)NLTK安裝 方法一:使用 nltk 自帶的 download() 下載,由于國(guó)內(nèi)網(wǎng)絡(luò)問(wèn)題,大概率失敗。 方法二:從下載文件手動(dòng)安裝包。 鏈接:https://pan.baidu.com/s/1nQveCEAucFSNbuOAsrs6yw?pwd=yydh 提取碼:yydh 從百度網(wǎng)盤下載nlt

    2024年01月20日
    瀏覽(30)
  • WPF項(xiàng)目創(chuàng)建HTTP WEB服務(wù),不使用IIS業(yè)務(wù) WPF桌面程序WebApi WPF 集成WebApi C# 創(chuàng)建HTTP Web API服務(wù)

    WPF項(xiàng)目創(chuàng)建HTTP WEB服務(wù),不使用IIS業(yè)務(wù) WPF桌面程序WebApi WPF 集成WebApi C# 創(chuàng)建HTTP Web API服務(wù)

    在C# WPF應(yīng)用程序中直接創(chuàng)建HTTP服務(wù)或WebAPI服務(wù)有以下優(yōu)點(diǎn): 自托管服務(wù): 簡(jiǎn)化部署:無(wú)需依賴外部服務(wù)器或IIS(Internet Information Services),可以直接在應(yīng)用程序內(nèi)部啟動(dòng)和運(yùn)行Web服務(wù)。 集成緊密:與WPF應(yīng)用程序的其他組件和邏輯可以更緊密地集成,因?yàn)樗鼈兌荚谕粋€(gè)進(jìn)程

    2024年02月02日
    瀏覽(87)
  • 使用IDEA部署Web項(xiàng)目到本地的Tomcat服務(wù)器

    使用IDEA部署Web項(xiàng)目到本地的Tomcat服務(wù)器

    1.1 Tomcat下載與安裝啟動(dòng) 下載地址:http://tomcat.apache.org/ (左側(cè)Download選擇下載版本) 1.1.1 安裝: 1、下載好了解壓到一個(gè)沒有特殊符號(hào)的目錄中(一般純英文即可) 2、進(jìn)入到解壓的目錄下找到binstartup.bat雙擊啟動(dòng)即可 tomcat需要配置JAVA_HOME環(huán)境變量,不要把bin目錄也配置到JAVA

    2024年02月13日
    瀏覽(23)
  • IntelliJ IDEA創(chuàng)建Web項(xiàng)目并使用Web服務(wù)器----Tomcat

    IntelliJ IDEA創(chuàng)建Web項(xiàng)目并使用Web服務(wù)器----Tomcat

    以下是本篇文章正文內(nèi)容,下面案例可供參考(提示:本篇文章屬于原創(chuàng),請(qǐng)轉(zhuǎn)發(fā)或者引用時(shí)注明出處。),大家記得支持一下?。。?! 每日清醒: ????慢慢來(lái),誰(shuí)還沒有一個(gè)努力的過(guò)程。?? 一定要注意:別忘了設(shè)置好之后點(diǎn)擊應(yīng)用?。。。。。。。?! maven項(xiàng)目的重點(diǎn)

    2024年02月10日
    瀏覽(30)
  • linux高并發(fā)web服務(wù)器開發(fā)(web服務(wù)器)18_函數(shù)解析http請(qǐng)求, 正則表達(dá)式,sscanf使用,http中數(shù)據(jù)特殊字符編碼解碼

    linux高并發(fā)web服務(wù)器開發(fā)(web服務(wù)器)18_函數(shù)解析http請(qǐng)求, 正則表達(dá)式,sscanf使用,http中數(shù)據(jù)特殊字符編碼解碼

    pdf詳情版 編寫函數(shù)解析http請(qǐng)求 ○ GET /hello.html HTTP/1.1rn ○ 將上述字符串分為三部分解析出來(lái) 編寫函數(shù)根據(jù)文件后綴,返回對(duì)應(yīng)的文件類型 sscanf - 讀取格式化的字符串中的數(shù)據(jù) ○ 使用正則表達(dá)式拆分 ○ [^ ]的用法 通過(guò)瀏覽器請(qǐng)求目錄數(shù)據(jù) ○ 讀指定目錄內(nèi)容 ? opendir ?

    2024年02月16日
    瀏覽(27)
  • 使用 cpolar 內(nèi)網(wǎng)穿透將本地 web 網(wǎng)站發(fā)布上線(無(wú)需服務(wù)器)

    使用 cpolar 內(nèi)網(wǎng)穿透將本地 web 網(wǎng)站發(fā)布上線(無(wú)需服務(wù)器)

    當(dāng)我們以本地電腦做服務(wù)器搭建web網(wǎng)站時(shí),如何將它發(fā)布到互聯(lián)網(wǎng)上,實(shí)現(xiàn)公網(wǎng)用戶都可以訪問(wèn)內(nèi)網(wǎng)的web網(wǎng)站就變得很重要。 這里我們以macOS系統(tǒng)自帶的Apache為例,在本地啟用Apache服務(wù)器,并通過(guò)cpolar內(nèi)網(wǎng)穿透將其暴露至公網(wǎng),實(shí)現(xiàn)在外公網(wǎng)環(huán)境下訪問(wèn)本地web服務(wù),無(wú)需購(gòu)買

    2024年01月23日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包