{"id":26160,"date":"2025-04-19T14:43:00","date_gmt":"2025-04-19T06:43:00","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/26160.html"},"modified":"2025-04-19T14:43:00","modified_gmt":"2025-04-19T06:43:00","slug":"esp32%e7%b3%bb%e5%88%97%e5%9b%9b%ef%bc%9a%e6%90%ad%e5%bb%bahttp%e7%9a%84webserver%e7%9a%84%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/26160.html","title":{"rendered":"ESP32\u7cfb\u5217\u56db\uff1a\u642d\u5efahttp\u7684webserver\u7684\u670d\u52a1\u5668"},"content":{"rendered":"<p>\u6700\u8fd1\u5728\u4f7f\u7528ESP32\u642d\u5efaweb\u670d\u52a1\u5668\u6d4b\u8bd5&#xff0c;\u53d1\u73b0esp32\u642d\u5efa\u8fd9\u7c7b\u5f00\u53d1\u73af\u5883\u8fd8\u662f\u6bd4\u8f83\u65b9\u4fbf\u7684\u3002\u5177\u4f53\u7684http\u534f\u8bae\u8fd9\u91cc\u5c31\u4e0d\u518d\u8d58\u8ff0&#xff0c;\u6211\u4eec\u4e3b\u8981\u8bf4\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528ESP32\u63d0\u4f9b\u7684API\u6765\u642d\u5efa\u6211\u4eec\u7684http web\u3002<\/p>\n<p>\u4e00\u3001web\u670d\u52a1\u5668\u642d\u5efa\u8fc7\u7a0b<\/p>\n<p>1\u3001\u914d\u7f6eweb\u670d\u52a1\u5668<\/p>\n<p>\u5728ESP-IDF\u4e2d&#xff0c;Web\u670d\u52a1\u5668\u4f7f\u7528httpd\u7ec4\u4ef6\u5b9e\u73b0\u3002\u6211\u4eec\u9700\u8981\u5148\u521b\u5efahttpd_config_t\u7ed3\u6784\u4f53&#xff0c;\u6307\u5b9a\u670d\u52a1\u5668\u7684\u7aef\u53e3\u3001\u6700\u5927\u5e76\u53d1\u8fde\u63a5\u6570\u3001URI\u5339\u914d\u5904\u7406\u5668\u7b49\u9009\u9879\u3002\u7136\u540e&#xff0c;\u6211\u4eec\u901a\u8fc7\u8c03\u7528httpd_start\u51fd\u6570\u6765\u542f\u52a8Web\u670d\u52a1\u5668\u3002&#xff08;\u4f7f\u7528\u9ed8\u8ba4\u7684\u914d\u7f6e\u5c31\u53ef\u4ee5&#xff0c;\u5305\u62ec\u7aef\u53e3\u53f7\u90fd\u5df2\u7ecf\u9ed8\u8ba4\u914d\u7f6e\u597d\u4e86&#xff09;<\/p>\n<p>httpd_config_t config &#061; HTTPD_DEFAULT_CONFIG();<br \/>\nhttpd_handle_t server &#061; NULL;<\/p>\n<p>\/\/ \u8bbe\u7f6e\u670d\u52a1\u5668\u7aef\u53e3\u4e3a80<br \/>\nconfig.server_port &#061; 80;<\/p>\n<p>\/\/ \u521b\u5efaHTTP\u670d\u52a1\u5668\u53e5\u67c4<br \/>\nif (httpd_start(&amp;server, &amp;config) !&#061; ESP_OK) {<br \/>\n    printf(&#034;Error starting server!\\\\n&#034;);<br \/>\n    return;<br \/>\n}<\/p>\n<p>2\u3001 \u6ce8\u518c URI\u5904\u7406\u5668 \u5728Web\u670d\u52a1\u5668\u542f\u52a8\u540e&#xff0c;\u6211\u4eec\u9700\u8981\u4e3a\u4e0d\u540c\u7684URI\u6ce8\u518c\u5904\u7406\u5668\u51fd\u6570\u3002\u5f53Web\u670d\u52a1\u5668\u63a5\u6536\u5230\u8bf7\u6c42\u65f6&#xff0c;\u4f1a\u6839\u636e\u8bf7\u6c42\u7684URI\u9009\u62e9\u76f8\u5e94\u7684\u5904\u7406\u5668\u51fd\u6570\u8fdb\u884c\u5904\u7406\u3002\u5728ESP-IDF\u4e2d&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528httpd_register_uri_handler\u51fd\u6570\u6ce8\u518cURI\u5904\u7406\u5668\u3002\u8be5\u51fd\u6570\u7684\u539f\u578b\u5982\u4e0b<\/p>\n<p>esp_err_t httpd_register_uri_handler(httpd_handle_t hd, const httpd_uri_t *uri)<\/p>\n<p>\u5176\u4e2d&#xff0c;hd\u53c2\u6570\u4e3aHTTP\u670d\u52a1\u5668\u53e5\u67c4&#xff1b;uri\u53c2\u6570\u4e3a\u5305\u542bURI\u8def\u5f84\u3001HTTP\u65b9\u6cd5\u3001\u5904\u7406\u51fd\u6570\u7b49\u4fe1\u606f\u7684\u7ed3\u6784\u4f53\u6307\u9488\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>static const httpd_uri_t echo &#061; {<br \/>\n    .uri       &#061; &#034;\/&#034;,<br \/>\n    .method    &#061; HTTP_POST,<br \/>\n    .handler   &#061; echo_post_handler,<br \/>\n    .user_ctx  &#061; NULL<br \/>\n};<br \/>\nstatic esp_err_t echo_post_handler(httpd_req_t *req)<br \/>\n{<br \/>\n    char buf[100];<br \/>\n    \/\/ char ssid[10];<br \/>\n    \/\/ char pswd[10];<br \/>\n    int ret, remaining &#061; req-&gt;content_len;<\/p>\n<p>    while (remaining &gt; 0) {<br \/>\n        \/* Read the data for the request *\/<br \/>\n        if ((ret &#061; httpd_req_recv(req, buf,<br \/>\n                        MIN(remaining, sizeof(buf)))) &lt;&#061; 0) {<br \/>\n            if (ret &#061;&#061; HTTPD_SOCK_ERR_TIMEOUT) {<br \/>\n                \/* Retry receiving if timeout occurred *\/<br \/>\n                continue;<br \/>\n            }<br \/>\n            return ESP_FAIL;<br \/>\n        }<\/p>\n<p>        \/* Send back the same data *\/<br \/>\n        httpd_resp_send_chunk(req, buf, ret);<br \/>\n        remaining -&#061; ret;<\/p>\n<p>        esp_err_t e &#061; httpd_query_key_value(buf,&#034;ssid&#034;,wifi_name,sizeof(wifi_name));<br \/>\n        if(e &#061;&#061; ESP_OK) {<br \/>\n            printf(&#034;ssid &#061; %s\\\\r\\\\n&#034;,wifi_name);<br \/>\n        }<br \/>\n        else {<br \/>\n            printf(&#034;error &#061; %d\\\\r\\\\n&#034;,e);<br \/>\n        }<\/p>\n<p>        e &#061; httpd_query_key_value(buf,&#034;password&#034;,wifi_password,sizeof(wifi_password));<br \/>\n        if(e &#061;&#061; ESP_OK) {<br \/>\n            printf(&#034;pswd &#061; %s\\\\r\\\\n&#034;,wifi_password);<br \/>\n        }<br \/>\n        else {<br \/>\n            printf(&#034;error &#061; %d\\\\r\\\\n&#034;,e);<br \/>\n        }<br \/>\n        \/* Log data received *\/<br \/>\n        ESP_LOGI(TAG, &#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; RECEIVED DATA &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#034;);<br \/>\n        ESP_LOGI(TAG, &#034;%.*s&#034;, ret, buf);<br \/>\n        ESP_LOGI(TAG, &#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#034;);<br \/>\n    }<\/p>\n<p>    \/\/ End response<br \/>\n    httpd_resp_send_chunk(req, NULL, 0);<br \/>\n    if(strcmp(wifi_name ,&#034;\\\\0&#034;)!&#061;0 &amp;&amp; strcmp(wifi_password,&#034;\\\\0&#034;)!&#061;0)<br \/>\n    {<br \/>\n        xSemaphoreGive(ap_sem);<br \/>\n        ESP_LOGI(TAG, &#034;set wifi name and password successfully! goto station mode&#034;);<br \/>\n    }<br \/>\n    return ESP_OK;<br \/>\n}<\/p>\n<p>html\u7684\u7f51\u9875\u5982\u4e0b&#xff1a;\u8fd9\u4e2a\u7f51\u9875\u5305\u542b\u4e86\u6309\u94ae\u7684\u5b9a\u4e49&#xff0c;\u4ee5\u53ca\u53d1\u9001json\u683c\u5f0f\u7684\u6570\u636e\u3002<\/p>\n<p><span style=\"color:#fe2c24\">\u6700\u540e\u9001json\u6570\u636e\u7684\u65f6\u5019&#xff0c;\u8981\u7528JSON.stringify\u65b9\u6cd5\u683c\u5f0f\u5316data&#xff0c;\u5426\u5219esp32\u89e3\u6790json\u4f1a\u62a5\u9519&#xff0c;\u6b64\u5904\u4e00\u5b9a\u8981\u6ce8\u610f&#xff01;&#xff01;&#xff01; \u6574\u4f53html\u754c\u9762\u975e\u5e38\u7b80\u5355&#xff0c;\u6ca1\u6709\u57fa\u7840\u7684\u4e5f\u5f88\u5bb9\u6613\u8bfb\u61c2&#xff0c;\u91cc\u9762\u5199\u4e86\u4e00\u4e2ajs\u51fd\u6570&#xff0c;\u8be5\u51fd\u6570\u662f\u5728\u70b9\u51fb\u6309\u94ae\u7684\u65f6\u5019\u89e6\u53d1&#xff0c;\u529f\u80fd\u4e3b\u8981\u662f\u8bfb\u53d6\u6587\u672c\u6846\u8f93\u5165\u7684\u6570\u636e&#xff0c;\u5c06\u6570\u636e\u5c01\u88c5\u4e3ajson\u683c\u5f0f&#xff0c;\u7136\u540epost\u53d1\u9001\u6570\u636e&#xff0c;xhttp.open(\u201cPOST\u201d, \u201c\/wifi_data\u201d, true);\u4e2d\u7684url \u201c\/wifi_data\u201d\u548cesp32\u670d\u52a1\u7aef\u4e2d\u7684\u5b9a\u4e49\u8981\u4e00\u81f4&#xff0c;\u5426\u5219\u662f\u65e0\u6cd5\u6210\u529f\u7684\u3002<\/span><\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;head&gt;<br \/>\n    &lt;meta charset&#061;&#034;utf-8&#034;&gt;<br \/>\n    &lt;title&gt;Web server system&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;table class&#061;&#034;fixed&#034; border&#061;&#034;5&#034;&gt;<br \/>\n    &lt;col width&#061;&#034;1000px&#034; \/&gt;&lt;col width&#061;&#034;500px&#034; \/&gt;<br \/>\n    &lt;tr&gt;&lt;td&gt;<br \/>\n        &lt;h2 style&#061;&#034; text-align:center;&#034;&gt; **** Web Server ***&lt;\/h2&gt;<\/p>\n<p>        &lt;h3&gt;wifi \u5bc6\u7801\u914d\u7f6e&lt;\/h3&gt;<br \/>\n    &lt;div&gt;<br \/>\n        &lt;label for&#061;&#034;name&#034;&gt;wifi\u540d\u79f0&lt;\/label&gt;<br \/>\n        &lt;input type&#061;&#034;text&#034; id&#061;&#034;wifi&#034; name&#061;&#034;car_name&#034; placeholder&#061;&#034;ssid&#034;&gt;<br \/>\n        &lt;br&gt;<br \/>\n        &lt;label for&#061;&#034;type&#034;&gt;\u5bc6\u7801&lt;\/label&gt;<br \/>\n        &lt;input type&#061;&#034;text&#034; id&#061;&#034;code&#034; name&#061;&#034;car_type&#034; placeholder&#061;&#034;password&#034;&gt;<br \/>\n        &lt;br&gt;<br \/>\n        &lt;button id &#061;&#034;send_WIFI&#034; type&#061;&#034;button&#034; onclick&#061;&#034;send_wifi()&#034;&gt;\u63d0\u4ea4&lt;\/button&gt;<br \/>\n    &lt;\/div&gt;<br \/>\n    &lt;\/td&gt;&lt;td&gt;<br \/>\n        &lt;table border&#061;&#034;10&#034;&gt;<br \/>\n            &lt;tr&gt;<br \/>\n                &lt;td&gt;<br \/>\n                    &lt;label for&#061;&#034;newfile&#034;&gt;Upload a file&lt;\/label&gt;<br \/>\n                &lt;\/td&gt;<br \/>\n                &lt;td colspan&#061;&#034;2&#034;&gt;<br \/>\n                    &lt;input id&#061;&#034;newfile&#034; type&#061;&#034;file&#034; onchange&#061;&#034;setpath()&#034; style&#061;&#034;width:100%;&#034;&gt;<br \/>\n                &lt;\/td&gt;<br \/>\n            &lt;\/tr&gt;<br \/>\n            &lt;tr&gt;<br \/>\n                &lt;td&gt;<br \/>\n                    &lt;label for&#061;&#034;filepath&#034;&gt;Set path on server&lt;\/label&gt;<br \/>\n                &lt;\/td&gt;<br \/>\n                &lt;td&gt;<br \/>\n                    &lt;input id&#061;&#034;filepath&#034; type&#061;&#034;text&#034; style&#061;&#034;width:100%;&#034;&gt;<br \/>\n                &lt;\/td&gt;<br \/>\n                &lt;td&gt;<br \/>\n                    &lt;button id&#061;&#034;upload&#034; type&#061;&#034;button&#034; onclick&#061;&#034;upload()&#034;&gt;Upload&lt;\/button&gt;<br \/>\n                &lt;\/td&gt;<br \/>\n            &lt;\/tr&gt;<br \/>\n        &lt;\/table&gt;<br \/>\n    &lt;\/td&gt;&lt;\/tr&gt;<br \/>\n&lt;\/table&gt;<br \/>\n&lt;script&gt;<br \/>\nfunction setpath() {<br \/>\n    var default_path &#061; document.getElementById(&#034;newfile&#034;).files[0].name;<br \/>\n    document.getElementById(&#034;filepath&#034;).value &#061; default_path;<br \/>\n}<br \/>\nfunction upload() {<br \/>\n    var filePath &#061; document.getElementById(&#034;filepath&#034;).value;<br \/>\n    var upload_path &#061; &#034;\/upload\/&#034; &#043; filePath;<br \/>\n    var fileInput &#061; document.getElementById(&#034;newfile&#034;).files;<\/p>\n<p>    \/* Max size of an individual file. Make sure this<br \/>\n     * value is same as that set in file_server.c *\/<br \/>\n    var MAX_FILE_SIZE &#061; 200*1024;<br \/>\n    var MAX_FILE_SIZE_STR &#061; &#034;200KB&#034;;<\/p>\n<p>    if (fileInput.length &#061;&#061; 0) {<br \/>\n        alert(&#034;No file selected!&#034;);<br \/>\n    } else if (filePath.length &#061;&#061; 0) {<br \/>\n        alert(&#034;File path on server is not set!&#034;);<br \/>\n    } else if (filePath.indexOf(&#039; &#039;) &gt;&#061; 0) {<br \/>\n        alert(&#034;File path on server cannot have spaces!&#034;);<br \/>\n    } else if (filePath[filePath.length-1] &#061;&#061; &#039;\/&#039;) {<br \/>\n        alert(&#034;File name not specified after path!&#034;);<br \/>\n    } else if (fileInput[0].size &gt; 200*1024) {<br \/>\n        alert(&#034;File size must be less than 200KB!&#034;);<br \/>\n    } else {<br \/>\n        document.getElementById(&#034;newfile&#034;).disabled &#061; true;<br \/>\n        document.getElementById(&#034;filepath&#034;).disabled &#061; true;<br \/>\n        document.getElementById(&#034;upload&#034;).disabled &#061; true;<\/p>\n<p>        var file &#061; fileInput[0];<br \/>\n        var xhttp &#061; new XMLHttpRequest();<br \/>\n        xhttp.onreadystatechange &#061; function() {<br \/>\n            if (xhttp.readyState &#061;&#061; 4) {<br \/>\n                if (xhttp.status &#061;&#061; 200) {<br \/>\n                    document.open();<br \/>\n                    document.write(xhttp.responseText);<br \/>\n                    document.close();<br \/>\n                } else if (xhttp.status &#061;&#061; 0) {<br \/>\n                    alert(&#034;Server closed the connection abruptly!&#034;);<br \/>\n                    location.reload()<br \/>\n                } else {<br \/>\n                    alert(xhttp.status &#043; &#034; Error!\\\\n&#034; &#043; xhttp.responseText);<br \/>\n                    location.reload()<br \/>\n                }<br \/>\n            }<br \/>\n        };<br \/>\n        xhttp.open(&#034;POST&#034;, upload_path, true);<br \/>\n        xhttp.send(file);<br \/>\n    }<br \/>\n}<\/p>\n<p>function send_wifi() {<br \/>\n    var input_ssid &#061; document.getElementById(&#034;wifi&#034;).value;<br \/>\n    var input_code &#061; document.getElementById(&#034;code&#034;).value;<br \/>\n    var xhttp &#061; new XMLHttpRequest();<br \/>\n        xhttp.open(&#034;POST&#034;, &#034;\/wifi_data&#034;, true);<br \/>\n        xhttp.onreadystatechange &#061; function() {<br \/>\n            if (xhttp.readyState &#061;&#061; 4) {<br \/>\n                if (xhttp.status &#061;&#061; 200) {<br \/>\n                    console.log(xhttp.responseText);<br \/>\n                } else if (xhttp.status &#061;&#061; 0) {<br \/>\n                    alert(&#034;Server closed the connection abruptly!&#034;);<br \/>\n                    location.reload()<br \/>\n                } else {<br \/>\n                    alert(xhttp.status &#043; &#034; Error!\\\\n&#034; &#043; xhttp.responseText);<br \/>\n                    location.reload()<br \/>\n                }<br \/>\n            }<br \/>\n        };<br \/>\n    var data &#061; {<br \/>\n        &#034;wifi_name&#034;:input_ssid,<br \/>\n        &#034;wifi_code&#034;:input_code<br \/>\n    }<br \/>\n        xhttp.send(JSON.stringify(data));<br \/>\n}<\/p>\n<p>&lt;\/script&gt;<\/p>\n<\/p>\n<p>static esp_err_t html_default_get_handler(httpd_req_t *req)<br \/>\n{<br \/>\n    \/\/ \/* Send HTML file header *\/<br \/>\n    \/\/ httpd_resp_sendstr_chunk(req, &#034;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;body&gt;&#034;);<\/p>\n<p>    \/* Get handle to embedded file upload script *\/<br \/>\n    extern const unsigned char upload_script_start[] asm(&#034;_binary_upload_script_html_start&#034;);<br \/>\n    extern const unsigned char upload_script_end[] asm(&#034;_binary_upload_script_html_end&#034;);<br \/>\n    const size_t upload_script_size &#061; (upload_script_end &#8211; upload_script_start);<\/p>\n<p>    \/* Add file upload form and script which on execution sends a POST request to \/upload *\/<br \/>\n    httpd_resp_send_chunk(req, (const char *)upload_script_start, upload_script_size);<\/p>\n<p>    \/* Send remaining chunk of HTML file to complete it *\/<br \/>\n    httpd_resp_sendstr_chunk(req, &#034;&lt;\/body&gt;&lt;\/html&gt;&#034;);<\/p>\n<p>    \/* Send empty chunk to signal HTTP response completion *\/<br \/>\n    httpd_resp_sendstr_chunk(req, NULL);<br \/>\n    return ESP_OK;<br \/>\n}<\/p>\n<p>    httpd_uri_t html_default &#061; {<br \/>\n        .uri &#061; &#034;\/&#034;, \/\/ Match all URIs of type \/path\/to\/file<br \/>\n        .method &#061; HTTP_GET,<br \/>\n        .handler &#061; html_default_get_handler,<br \/>\n        .user_ctx &#061; &#034;html&#034; \/\/ Pass server data as context<br \/>\n    };<\/p>\n<p>    httpd_register_uri_handler(server, &amp;html_default); <\/p>\n<p><span style=\"color:#ff9900\">\u8fd9\u91cc\u8981\u7279\u522b\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">1&#xff09;\u3001.uri &#061; &#034;\/&#034;,\u8fd9\u4e2a\u8868\u793a\u5f53\u4f60\u6253\u5f00\u7f51\u9875\u7684IP\u5730\u5740\u540e\u7b2c\u4e00\u4e2a\u8981\u663e\u793a\u7684\u9875\u9762&#xff0c;\u4e5f\u5c31\u662f\u8981\u653e\u5230\u6839\u76ee\u5f55\u4e0b&#xff08;&#034;\/&#034;\u4e5f\u5c31\u662f\u6839\u76ee\u5f55&#xff09;\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">2&#xff09;\u3001ESP32\u53ef\u4ee5\u76f4\u63a5\u5c06html\u7684\u7f51\u9875\u7f16\u8bd1\u8fdb\u6765\u4e0d\u9700\u8981\u8f6c\u4e3a\u6570\u7ec4&#xff0c;\u4f46\u5728<\/span><span style=\"color:#fe2c24\">CMakeList.txt\u6587\u4ef6\u4e2d\u9700\u8981EMBED_FILES upload_script.html<\/span><span style=\"color:#0d0016\">\u8fd9<\/span>\u6837\u7684\u5f62\u5f0f\u5f15\u5165\u7f51\u9875\u6587\u4ef6\u3002\u8fd9\u4e2ahtml\u7f16\u8bd1\u51fa\u51fa\u6765\u7684\u6587\u672c\u6587\u4ef6\u600e\u4e48\u4f7f\u7528\u5462\u3002wifi.html\u7f16\u8bd1\u51fa\u6765\u4e00\u822c\u540d\u79f0\u662f\u9ed8\u8ba4\u7684_binary_\u540d\u79f0_\u7c7b\u578b_start\u3002\u8fd9\u4e2a\u6307\u9488\u4ee3\u7f16\u8bd1\u51fa\u6765\u6587\u4ef6\u7684\u8d77\u59cb\u5730\u5740\u3002_binary_\u540d\u79f0_\u7c7b\u578b_end&#xff0c;\u4ee3\u8868\u7ed3\u675f\u5730\u5740\u3002wifi.html\u7684\u5f15\u7528\u65b9\u5f0f\u5982\u4e0b\u3002\u901a\u8fc7\u4ee5\u4e0b\u7684\u65b9\u5f0f\u5c31\u53ef\u4ee5\u83b7\u5f97html\u8fd9\u4e2a\u5927\u6570\u7ec4\u3002<\/p>\n<p>    extern const unsigned char upload_script_start[] asm(&#034;_binary_upload_script_html_start&#034;);<br \/>\n    extern const unsigned char upload_script_end[] asm(&#034;_binary_upload_script_html_end&#034;);<br \/>\n    const size_t upload_script_size &#061; (upload_script_end &#8211; upload_script_start);<\/p>\n<p>    \/* Add file upload form and script which on execution sends a POST request to \/upload *\/<br \/>\n    httpd_resp_send_chunk(req, (const char *)upload_script_start, upload_script_size);<\/p>\n<p><span style=\"color:#0d0016\">3\u3001\u5b9e\u73b0URI\u5904\u7406\u51fd\u6570<\/span><\/p>\n<p>\u5728\u6ce8\u518cURI\u5904\u7406\u5668\u540e&#xff0c;\u6211\u4eec\u9700\u8981\u5b9e\u73b0\u5bf9\u5e94\u7684\u5904\u7406\u5668\u51fd\u6570\u3002URI\u5904\u7406\u5668\u51fd\u6570\u7684\u539f\u578b\u4e3a&#xff1a;<\/p>\n<p>typedef esp_err_t (*httpd_uri_func_t)(httpd_req_t *req);<\/p>\n<p>\u5982\u4e0a\u9762\u793a\u4f8b\u4e2d\u7684&#xff1a;<\/p>\n<p>static esp_err_t html_default_get_handler(httpd_req_t *req) <\/p>\n<p>4\u3001\u5904\u7406HTTP\u8bf7\u6c42 \u5728URI\u5904\u7406\u5668\u51fd\u6570\u4e2d&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7HTTP\u8bf7\u6c42\u4fe1\u606f\u7ed3\u6784\u4f53\u6307\u9488httpd_req_t\u83b7\u53d6HTTP\u8bf7\u6c42\u7684\u5404\u79cd\u53c2\u6570\u548c\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684HTTP\u8bf7\u6c42\u5904\u7406\u51fd\u6570&#xff1a;<\/p>\n<p>httpd_req_get_hdr_value_str&#xff1a;\u83b7\u53d6HTTP\u8bf7\u6c42\u5934\u4e2d\u6307\u5b9a\u5b57\u6bb5\u7684\u503c&#xff08;\u5b57\u7b26\u4e32\u683c\u5f0f&#xff09; httpd_req_get_url_query_str&#xff1a;\u83b7\u53d6HTTP\u8bf7\u6c42URL\u4e2d\u7684\u67e5\u8be2\u53c2\u6570&#xff08;\u5b57\u7b26\u4e32\u683c\u5f0f&#xff09; httpd_query_key_value&#xff1a;\u89e3\u6790HTTP\u8bf7\u6c42URL\u4e2d\u7684\u67e5\u8be2\u53c2\u6570&#xff0c;\u83b7\u53d6\u6307\u5b9a\u53c2\u6570\u540d\u7684\u503c&#xff08;\u5b57\u7b26\u4e32\u683c\u5f0f&#xff09; httpd_req_recv&#xff1a;\u4eceHTTP\u8bf7\u6c42\u63a5\u6536\u6570\u636e httpd_req_send&#xff1a;\u53d1\u9001HTTP\u54cd\u5e94\u6570\u636e httpd_resp_set_type&#xff1a;\u8bbe\u7f6eHTTP\u54cd\u5e94\u5185\u5bb9\u7684MIME\u7c7b\u578b httpd_resp_send_chunk&#xff1a;\u5206\u5757\u53d1\u9001HTTP\u54cd\u5e94\u6570\u636e\u3002 \u4f8b\u5982&#xff0c;\u4ee5\u4e0b\u662f\u4e00\u4e2aURI\u5904\u7406\u5668\u51fd\u6570\u7684\u793a\u4f8b&#xff0c;\u7528\u4e8e\u5904\u7406\/echo\u8def\u5f84\u7684POST\u8bf7\u6c42&#xff1a;<\/p>\n<p>static esp_err_t echo_post_handler(httpd_req_t *req)<br \/>\n{<br \/>\n    char buf[1024];<br \/>\n    int ret, remaining &#061; req-&gt;content_len;<\/p>\n<p>    \/\/ \u4eceHTTP\u8bf7\u6c42\u4e2d\u63a5\u6536\u6570\u636e<br \/>\n    while (remaining &gt; 0) {<br \/>\n        ret &#061; httpd_req_recv(req, buf, MIN(remaining, sizeof(buf)));<br \/>\n        if (ret &lt;&#061; 0) {<br \/>\n            if (ret &#061;&#061; HTTPD_SOCK_ERR_TIMEOUT) {<br \/>\n                \/\/ \u5904\u7406\u8d85\u65f6<br \/>\n                httpd_resp_send_408(req);<br \/>\n            }<br \/>\n            return ESP_FAIL;<br \/>\n        }<\/p>\n<p>        \/\/ \u5904\u7406\u63a5\u6536\u5230\u7684\u6570\u636e<br \/>\n        \/\/ &#8230;<\/p>\n<p>        remaining -&#061; ret;<br \/>\n    }<\/p>\n<p>    \/\/ \u53d1\u9001HTTP\u54cd\u5e94<br \/>\n    httpd_resp_set_type(req, HTTPD_TYPE_TEXT);<br \/>\n    httpd_resp_send(req, &#034;Received data: &#034;, -1);<br \/>\n    httpd_resp_send_chunk(req, buf, req-&gt;content_len);<br \/>\n    httpd_resp_send_chunk(req, NULL, 0);<\/p>\n<p>    return ESP_OK;<br \/>\n}<\/p>\n<p>5\u3001 \u53d1\u9001\u54cd\u5e94 \u5728URI\u5904\u7406\u51fd\u6570\u4e2d&#xff0c;\u53ef\u4ee5\u4f7f\u7528httpd_resp_send()\u51fd\u6570\u5c06\u54cd\u5e94\u53d1\u9001\u56de\u5ba2\u6237\u7aef\u3002\u8be5\u51fd\u6570\u9700\u8981\u4f20\u5165\u4e00\u4e2ahttpd_req_t\u7ed3\u6784\u4f53\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u8be5\u7ed3\u6784\u4f53\u8868\u793aHTTP\u8bf7\u6c42\u548c\u54cd\u5e94\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u5728\u4e0a\u9762\u7684hello_get_handler\u5904\u7406\u51fd\u6570\u4e2d&#xff0c;\u53ef\u4ee5\u4f7f\u7528httpd_resp_send()\u51fd\u6570\u5c06\u201cHello, World!\u201d\u5b57\u7b26\u4e32\u4f5c\u4e3a\u54cd\u5e94\u53d1\u9001\u56de\u5ba2\u6237\u7aef&#xff1a;<\/p>\n<p>static esp_err_t hello_get_handler(httpd_req_t *req)<br \/>\n{<br \/>\n    const char* resp_str &#061; &#034;Hello, World!&#034;;<br \/>\n    httpd_resp_send(req, resp_str, strlen(resp_str));<br \/>\n    return ESP_OK;<br \/>\n}<\/p>\n<p>\u4e8c\u3001\u4e3b\u8981\u4f7f\u7528API\u7684\u8bf4\u660e1. httpd_register_uri_handler \u7528\u4e8e\u5c06HTTP\u8bf7\u6c42\u7684URI\u8def\u7531\u5230\u5904\u7406\u7a0b\u5e8f\u3002\u8fd9\u4e2a\u51fd\u6570\u63a5\u6536\u4e24\u4e2a\u53c2\u6570&#xff1a;httpd_handle_t\u7c7b\u578b\u7684HTTP\u670d\u52a1\u5668\u53e5\u67c4\u548chttpd_uri_t\u7c7b\u578b\u7684URI\u914d\u7f6e\u3002<\/p>\n<p>2. httpd_handle_t httpd_handle_t\u662fHTTP\u670d\u52a1\u5668\u7684\u4e00\u4e2a\u53e5\u67c4&#xff0c;\u5b83\u662f\u901a\u8fc7httpd_start\u51fd\u6570\u521b\u5efa\u7684\u3002\u800chttpd_uri_t\u5219\u5b9a\u4e49\u4e86HTTP\u8bf7\u6c42\u7684URI\u4fe1\u606f&#xff0c;\u5305\u62ecURI\u8def\u5f84\u3001HTTP\u8bf7\u6c42\u65b9\u6cd5\u548c\u5904\u7406\u51fd\u6570\u7b49\u3002<\/p>\n<p>3. httpd_query_key_value\u83b7\u53d6\u53d8\u91cf\u503c<span style=\"color:#ff9900\">httpd_query_key_value <\/span>\u7528\u4e8e\u4ece\u67e5\u8be2\u5b57\u7b26\u4e32\u4e2d\u83b7\u53d6\u6307\u5b9a\u952e\u7684\u503c\u3002\u67e5\u8be2\u5b57\u7b26\u4e32\u662f\u6307URL\u4e2d?\u540e\u9762\u7684\u90e8\u5206&#xff0c;\u5305\u542b\u591a\u4e2a\u952e\u503c\u5bf9&#xff0c;\u6bcf\u4e2a\u952e\u503c\u5bf9\u4e4b\u95f4\u4f7f\u7528&amp;\u5206\u9694\u3002\u4f8b\u5982&#xff0c;\u5bf9\u4e8e\u4ee5\u4e0bURL&#xff1a;<span style=\"color:#ff9900\">http:\/\/192.168.1.1\/path\/to\/handler?key1&#061;value1&amp;key2&#061;value2<\/span> \u83b7\u53d6\u5176\u4e2d\u7684&#xff1a;<span style=\"color:#ff9900\">esp_err_t httpd_query_key_value(const char *query, const char *key, char *buf, size_t buf_len);<\/span><\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u4f7f\u7528\u793a\u4f8b<\/p>\n<p>char query_str[] &#061; &#034;key1&#061;value1&amp;key2&#061;value2&#034;;<br \/>\nchar key[] &#061; &#034;key1&#034;;<br \/>\nchar value[16];<\/p>\n<p>if (httpd_query_key_value(query_str, key, value, sizeof(value)) &#061;&#061; ESP_OK) {<br \/>\n    printf(&#034;value&#061;%s\\\\n&#034;, value);<br \/>\n} else {<br \/>\n    printf(&#034;key not found\\\\n&#034;);<br \/>\n}<\/p>\n<h4>4. \u83b7\u53d6get\u53c2\u6570\u793a\u4f8b<\/h4>\n<p>\u4e0b\u9762\u5b9a\u4e49\u7684 handler \u6f14\u793a\u4e86\u5982\u4f55\u4ece\u8bf7\u6c42\u53c2\u6570\u91cc\u89e3\u6790 \u5b57\u7b26\u4e32param1\u548c\u6574\u578b\u53d8\u91cfparam2&#xff1a;<\/p>\n<p> esp_err_t index_handler(httpd_req_t *req)<br \/>\n{<br \/>\n     char* query_str &#061; NULL;<br \/>\n     char param1_value[10] &#061; {0};<br \/>\n     int param2_value&#061;0;<\/p>\n<p>     query_str &#061; strstr(req-&gt;uri, &#034;?&#034;);<br \/>\n     if(query_str!&#061;NULL){<br \/>\n         query_str &#043;&#043;;<br \/>\n         httpd_query_key_value(query_str, &#034;param1&#034;, param1_value, sizeof(param1_value));<br \/>\n         char param2_str[10] &#061; {0};<br \/>\n         httpd_query_key_value(query_str, &#034;param2&#034;, param2_str, sizeof(param2_str));<br \/>\n         param2_value &#061; atoi(param2_str);<br \/>\n     }<\/p>\n<p>     char resp_str[50] &#061; {0};<br \/>\n     snprintf(resp_str, sizeof(resp_str), &#034;param1&#061;%s, param2&#061;%d&#034;, param1_value, param2_value);<br \/>\n    httpd_resp_send(req, resp_str, strlen(resp_str));<br \/>\n    return ESP_OK;<br \/>\n}<\/p>\n<h4>5. \u83b7\u53d6post\u53c2\u6570\u793a\u4f8b<\/h4>\n<p>\u4e0b\u9762\u7684\u793a\u4f8b\u4ee3\u7801\u4e2d\u6839\u636ehttpd_req_t\u7684content_len\u6765\u5206\u914d\u4e00\u4e2a\u7f13\u51b2\u533a&#xff0c;\u5e76\u89e3\u6790\u8bf7\u6c42\u4e2d\u7684POST\u53c2\u6570&#xff1a;<\/p>\n<p> esp_err_t post_demo_handler(httpd_req_t *req)<br \/>\n{<br \/>\n    char post_string[64];<br \/>\n    int post_int&#061;0;<\/p>\n<p>    if (req-&gt;content_len &gt; 0)<br \/>\n    {<br \/>\n        \/\/ \u4ece\u8bf7\u6c42\u4f53\u4e2d\u8bfb\u53d6POST\u53c2\u6570<br \/>\n        char *buf &#061; malloc(req-&gt;content_len &#043; 1);<br \/>\n        int ret &#061; httpd_req_recv(req, buf, req-&gt;content_len);<br \/>\n        if (ret &lt;&#061; 0)<br \/>\n        {<br \/>\n            \/\/ \u63a5\u6536\u6570\u636e\u51fa\u9519<br \/>\n            free(buf);<br \/>\n            return ESP_FAIL;<br \/>\n        }<br \/>\n        buf[req-&gt;content_len] &#061; &#039;\\\\0&#039;;<\/p>\n<p>        \/\/ \u89e3\u6790POST\u53c2\u6570<br \/>\n        char *param_str;<br \/>\n        param_str &#061; strtok(buf, &#034;&amp;&#034;);<br \/>\n        while (param_str !&#061; NULL)<br \/>\n        {<br \/>\n            char *value_str &#061; strchr(param_str, &#039;&#061;&#039;);<br \/>\n            if (value_str !&#061; NULL)<br \/>\n            {<br \/>\n                *value_str&#043;&#043; &#061; &#039;\\\\0&#039;;<br \/>\n                if (strcmp(param_str, &#034;post_string&#034;) &#061;&#061; 0)<br \/>\n                {<br \/>\n                    strncpy(post_string, value_str, sizeof(post_string));<br \/>\n                }<br \/>\n                else if (strcmp(param_str, &#034;post_int&#034;) &#061;&#061; 0)<br \/>\n                {<br \/>\n                    post_int &#061; atoi(value_str);<br \/>\n                }<br \/>\n            }<br \/>\n            param_str &#061; strtok(NULL, &#034;&amp;&#034;);<br \/>\n        }<\/p>\n<p>        free(buf);<br \/>\n    }<\/p>\n<p>    \/\/ \u5c06\u7ed3\u679c\u6253\u5370\u8f93\u51fa<br \/>\n    printf(&#034;post_string&#061;%s, post_int&#061;%d\\\\n&#034;, post_string, post_int);<\/p>\n<p>    \/\/ \u8fd4\u56de\u6210\u529f<br \/>\n    httpd_resp_send(req, NULL, 0);<br \/>\n    return ESP_OK;<br \/>\n}<\/p>\n<p> httpd_uri_t post_uri &#061; {<br \/>\n         .uri &#061; &#034;\/post&#034;,<br \/>\n         .method &#061; HTTP_POST,<br \/>\n         .handler &#061; post_demo_handler,<br \/>\n         .user_ctx &#061; NULL<br \/>\n };<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1w\u6b21\uff0c\u70b9\u8d5e30\u6b21\uff0c\u6536\u85cf99\u6b21\u3002\u6700\u8fd1\u5728\u4f7f\u7528ESP32\u642d\u5efaweb\u670d\u52a1\u5668\u6d4b\u8bd5\uff0c\u53d1\u73b0esp32\u642d\u5efa\u8fd9\u7c7b\u5f00\u53d1\u73af\u5883\u8fd8\u662f\u6bd4\u8f83\u65b9\u4fbf\u7684\u3002\u5177\u4f53\u7684http\u534f\u8bae\u8fd9\u91cc\u5c31\u4e0d\u518d\u8d58\u8ff0\uff0c\u6211\u4eec\u4e3b\u8981\u8bf4\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528ESP32\u63d0\u4f9b\u7684API\u6765\u642d\u5efa\u6211\u4eec\u7684http web\u3002\u4e00\u3001web\u670d\u52a1\u5668\u642d\u5efa\u8fc7\u7a0b1\u3001\u914d\u7f6eweb\u670d\u52a1\u5668\u5728\u4e2d\uff0cWeb\u670d\u52a1\u5668\u4f7f\u7528httpd\u7ec4\u4ef6\u5b9e\u73b0\u3002\u6211\u4eec\u9700\u8981\u5148\u521b\u5efahttpd_config_t\u7ed3\u6784\u4f53\uff0c\u6307\u5b9a\u670d\u52a1\u5668\u7684\u7aef\u53e3\u3001\u6700\u5927\u5e76\u53d1\u8fde\u63a5\u6570\u3001URI\u5339\u914d\u5904\u7406\u5668\u7b49\u9009\u9879\u3002\u7136\u540e\uff0c\u6211\u4eec\u901a\u8fc7\u8c03\u7528httpd_start\u51fd\u6570\u6765\u542f\u52a8Web\u670d\u52a1\u5668\u3002_esp32 webserver<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[179,151,191],"topic":[],"class_list":["post-26160","post","type-post","status-publish","format-standard","hentry","category-server","tag-esp32","tag-http","tag-191"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>ESP32\u7cfb\u5217\u56db\uff1a\u642d\u5efahttp\u7684webserver\u7684\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/26160.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ESP32\u7cfb\u5217\u56db\uff1a\u642d\u5efahttp\u7684webserver\u7684\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1w\u6b21\uff0c\u70b9\u8d5e30\u6b21\uff0c\u6536\u85cf99\u6b21\u3002\u6700\u8fd1\u5728\u4f7f\u7528ESP32\u642d\u5efaweb\u670d\u52a1\u5668\u6d4b\u8bd5\uff0c\u53d1\u73b0esp32\u642d\u5efa\u8fd9\u7c7b\u5f00\u53d1\u73af\u5883\u8fd8\u662f\u6bd4\u8f83\u65b9\u4fbf\u7684\u3002\u5177\u4f53\u7684http\u534f\u8bae\u8fd9\u91cc\u5c31\u4e0d\u518d\u8d58\u8ff0\uff0c\u6211\u4eec\u4e3b\u8981\u8bf4\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528ESP32\u63d0\u4f9b\u7684API\u6765\u642d\u5efa\u6211\u4eec\u7684http web\u3002\u4e00\u3001web\u670d\u52a1\u5668\u642d\u5efa\u8fc7\u7a0b1\u3001\u914d\u7f6eweb\u670d\u52a1\u5668\u5728\u4e2d\uff0cWeb\u670d\u52a1\u5668\u4f7f\u7528httpd\u7ec4\u4ef6\u5b9e\u73b0\u3002\u6211\u4eec\u9700\u8981\u5148\u521b\u5efahttpd_config_t\u7ed3\u6784\u4f53\uff0c\u6307\u5b9a\u670d\u52a1\u5668\u7684\u7aef\u53e3\u3001\u6700\u5927\u5e76\u53d1\u8fde\u63a5\u6570\u3001URI\u5339\u914d\u5904\u7406\u5668\u7b49\u9009\u9879\u3002\u7136\u540e\uff0c\u6211\u4eec\u901a\u8fc7\u8c03\u7528httpd_start\u51fd\u6570\u6765\u542f\u52a8Web\u670d\u52a1\u5668\u3002_esp32 webserver\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/26160.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-19T06:43:00+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/26160.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/26160.html\",\"name\":\"ESP32\u7cfb\u5217\u56db\uff1a\u642d\u5efahttp\u7684webserver\u7684\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-19T06:43:00+00:00\",\"dateModified\":\"2025-04-19T06:43:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/26160.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/26160.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/26160.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ESP32\u7cfb\u5217\u56db\uff1a\u642d\u5efahttp\u7684webserver\u7684\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ESP32\u7cfb\u5217\u56db\uff1a\u642d\u5efahttp\u7684webserver\u7684\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/26160.html","og_locale":"zh_CN","og_type":"article","og_title":"ESP32\u7cfb\u5217\u56db\uff1a\u642d\u5efahttp\u7684webserver\u7684\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1w\u6b21\uff0c\u70b9\u8d5e30\u6b21\uff0c\u6536\u85cf99\u6b21\u3002\u6700\u8fd1\u5728\u4f7f\u7528ESP32\u642d\u5efaweb\u670d\u52a1\u5668\u6d4b\u8bd5\uff0c\u53d1\u73b0esp32\u642d\u5efa\u8fd9\u7c7b\u5f00\u53d1\u73af\u5883\u8fd8\u662f\u6bd4\u8f83\u65b9\u4fbf\u7684\u3002\u5177\u4f53\u7684http\u534f\u8bae\u8fd9\u91cc\u5c31\u4e0d\u518d\u8d58\u8ff0\uff0c\u6211\u4eec\u4e3b\u8981\u8bf4\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528ESP32\u63d0\u4f9b\u7684API\u6765\u642d\u5efa\u6211\u4eec\u7684http web\u3002\u4e00\u3001web\u670d\u52a1\u5668\u642d\u5efa\u8fc7\u7a0b1\u3001\u914d\u7f6eweb\u670d\u52a1\u5668\u5728\u4e2d\uff0cWeb\u670d\u52a1\u5668\u4f7f\u7528httpd\u7ec4\u4ef6\u5b9e\u73b0\u3002\u6211\u4eec\u9700\u8981\u5148\u521b\u5efahttpd_config_t\u7ed3\u6784\u4f53\uff0c\u6307\u5b9a\u670d\u52a1\u5668\u7684\u7aef\u53e3\u3001\u6700\u5927\u5e76\u53d1\u8fde\u63a5\u6570\u3001URI\u5339\u914d\u5904\u7406\u5668\u7b49\u9009\u9879\u3002\u7136\u540e\uff0c\u6211\u4eec\u901a\u8fc7\u8c03\u7528httpd_start\u51fd\u6570\u6765\u542f\u52a8Web\u670d\u52a1\u5668\u3002_esp32 webserver","og_url":"https:\/\/www.wsisp.com\/helps\/26160.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-19T06:43:00+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/26160.html","url":"https:\/\/www.wsisp.com\/helps\/26160.html","name":"ESP32\u7cfb\u5217\u56db\uff1a\u642d\u5efahttp\u7684webserver\u7684\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-19T06:43:00+00:00","dateModified":"2025-04-19T06:43:00+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/26160.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/26160.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/26160.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"ESP32\u7cfb\u5217\u56db\uff1a\u642d\u5efahttp\u7684webserver\u7684\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/26160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=26160"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/26160\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=26160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=26160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=26160"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=26160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}