{"id":20249,"date":"2025-04-19T02:59:08","date_gmt":"2025-04-18T18:59:08","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/20249.html"},"modified":"2025-04-19T02:59:08","modified_gmt":"2025-04-18T18:59:08","slug":"%e4%b8%80http-%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%ef%bc%88basic-authentication%ef%bc%89%e5%8e%9f%e7%90%86%e8%bf%87%e7%a8%8b%e4%bb%a5%e5%8f%8aesp32-idf%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%92%8c%e5%ae%a2","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/20249.html","title":{"rendered":"(\u4e00)HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09\u539f\u7406\u8fc7\u7a0b,\u4ee5\u53caesp32 idf\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4f8b\u7a0b"},"content":{"rendered":"<h3>\u524d\u8a00:\u901a\u8fc7\u540c\u65f6\u8bb2\u8bc9\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684\u5904\u7406\u60c5\u51b5,\u6765\u7406\u901a\u601d\u7ef4,\u4fbf\u4e8e\u7406\u89e3\u6574\u4e2aBasic Authentication\u8ba4\u8bc1\u8fc7\u7a0b.<\/h3>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418185906-6802a0faeb640.jpg\" \/><\/p>\n<h3>\u4e00.\u5148\u666e\u53ca\u4e00\u4e0b\u57fa\u7840\u77e5\u8bc6:<\/h3>\n<p>Base64\u00a0\u662f\u4e00\u79cd\u5c06\u4e8c\u8fdb\u5236\u6570\u636e\u8f6c\u6362\u4e3a ASCII \u5b57\u7b26\u4e32\u7684\u7f16\u7801\u65b9\u5f0f&#xff0c;\u4f7f\u7528 64 \u4e2a\u53ef\u6253\u5370\u5b57\u7b26&#xff08;A-Z, a-z, 0-9, &#043;, \/&#xff09;\u8868\u793a\u4e8c\u8fdb\u5236\u5185\u5bb9&#xff0c;\u5e76\u5728\u672b\u5c3e\u7528\u00a0&#061;\u00a0\u586b\u5145\u3002\u5176\u6838\u5fc3\u76ee\u7684\u662f\u89e3\u51b3\u4e8c\u8fdb\u5236\u6570\u636e\u5728\u7eaf\u6587\u672c\u534f\u8bae&#xff08;\u5982 HTTP&#xff09;\u4e2d\u4f20\u8f93\u65f6\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002<\/p>\n<p>HTTP \u57fa\u672c\u8ba4\u8bc1&#xff08;Basic Authentication&#xff09; \u4f5c\u7528&#xff1a;\u5c06\u7528\u6237\u540d\u548c\u5bc6\u7801\u62fc\u63a5\u4e3a username:password \u683c\u5f0f\u540e Base64 \u7f16\u7801&#xff0c;\u7f6e\u4e8e Authorization: Basic &lt;\u51ed\u8bc1&gt; \u5934\u4e2d\u4f20\u8f93\u3002\u4f8b\u5982:<\/p>\n<p>GET \/protected-resource HTTP\/1.1<\/p>\n<p>Authorization: Basic dXNlcjpwYXNzd2Q&#061; <\/p>\n<h6>Base64\u4f18\u52bf<\/h6>\n<li>\n<p>\u6587\u672c\u534f\u8bae\u517c\u5bb9\u6027 \u786e\u4fdd\u4e8c\u8fdb\u5236\u6570\u636e&#xff08;\u5982\u52a0\u5bc6\u54c8\u5e0c\u3001\u6587\u4ef6\u5185\u5bb9&#xff09;\u5728 HTTP \u5934\u6216 URL \u4e2d\u4e0d\u56e0\u975e ASCII \u5b57\u7b26\u88ab\u622a\u65ad\u6216\u8f6c\u4e49\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b80\u6613\u6027\u4e0e\u901a\u7528\u6027<\/p>\n<ul>\n<li>\u6240\u6709\u7f16\u7a0b\u8bed\u8a00\u5747\u652f\u6301 Base64 \u7f16\u89e3\u7801\u5e93&#xff08;\u5982 Python \u7684\u00a0base64\u3001C \u7684\u00a0mbedtls_base64&#xff09;\u3002<\/li>\n<li>\u65e0\u9700\u590d\u6742\u914d\u7f6e&#xff0c;\u9002\u5408\u5feb\u901f\u5b9e\u73b0\u8f7b\u91cf\u7ea7\u6570\u636e\u5c01\u88c5\u3002<\/li>\n<\/ul>\n<\/li>\n<h6>Base64\u5c40\u9650\u6027<\/h6>\n<li>\n<p>\u6570\u636e\u81a8\u80c0 Base64 \u7f16\u7801\u540e\u6570\u636e\u4f53\u79ef\u589e\u52a0\u7ea6\u00a033%&#xff08;\u6bcf 3 \u5b57\u8282\u4e8c\u8fdb\u5236\u6570\u636e\u6269\u5c55\u4e3a 4 \u5b57\u7b26&#xff09;&#xff0c;\u53ef\u80fd\u5f71\u54cd\u4f20\u8f93\u6548\u7387\u3002<\/p>\n<\/li>\n<li>\n<p>\u65e0\u52a0\u5bc6\u4fdd\u62a4 Base64 \u4ec5\u7f16\u7801\u800c\u975e\u52a0\u5bc6&#xff0c;\u653b\u51fb\u8005\u53ef\u8f7b\u6613\u89e3\u7801\u8fd8\u539f\u539f\u59cb\u6570\u636e&#xff08;\u5efa\u8bae\u914d\u5408 HTTPS \u5f25\u8865\u5b89\u5168\u6027&#xff09;\u3002<\/p>\n<\/li>\n<h3>\u4e8c.HTTP\u57fa\u672c\u8ba4\u8bc1\u7684\u539f\u7406<\/h3>\n<li>\u8ba4\u8bc1\u6d41\u7a0b\n<ul>\n<li>\u6b65\u9aa41&#xff1a;\u5ba2\u6237\u7aef\u9996\u6b21\u8bf7\u6c42 \u5ba2\u6237\u7aef\u53d1\u9001\u4e0d\u5e26\u8ba4\u8bc1\u4fe1\u606f\u7684HTTP\u8bf7\u6c42\u5230\u670d\u52a1\u5668\u53d7\u4fdd\u62a4\u8d44\u6e90:GET \/protected-resource HTTP\/1.1<\/li>\n<li>\u6b65\u9aa42&#xff1a;\u670d\u52a1\u5668\u8fd4\u56de\u8d28\u8be2&#xff08;Challenge&#xff09; \u670d\u52a1\u5668\u8fd4\u56de401 Unauthorized\u72b6\u6001\u7801&#xff0c;\u5e76\u5728\u54cd\u5e94\u5934\u4e2d\u6dfb\u52a0&#xff1a;WWW-Authenticate: Basic realm&#061;&#034;SecureArea&#034; \u5176\u4e2drealm\u5b9a\u4e49\u53d7\u4fdd\u62a4\u8d44\u6e90\u7684\u5b89\u5168\u57df&#xff0c;\u6d4f\u89c8\u5668\u4f1a\u5f39\u51fa\u7528\u6237\u540d\/\u5bc6\u7801\u8f93\u5165\u6846\u3002<\/li>\n<li>\u6b65\u9aa43&#xff1a;\u5ba2\u6237\u7aef\u53d1\u9001\u51ed\u8bc1 \u7528\u6237\u8f93\u5165\u51ed\u636e\u540e&#xff0c;\u5ba2\u6237\u7aef\u5c06username:password\u62fc\u63a5\u540e\u8fdb\u884cBase64\u7f16\u7801&#xff0c;\u751f\u6210Authorization\u5934&#xff1a;Authorization: Basic dXNlcjpwYXNzd29yZA&#061;&#061;<\/li>\n<li>\u6b65\u9aa44&#xff1a;\u670d\u52a1\u5668\u9a8c\u8bc1 \u670d\u52a1\u5668\u89e3\u7801Base64\u5b57\u7b26\u4e32&#xff0c;\u5206\u79bb\u7528\u6237\u540d\u548c\u5bc6\u7801\u8fdb\u884c\u6821\u9a8c&#xff0c;\u901a\u8fc7\u5219\u8fd4\u56de\u8d44\u6e90&#xff0c;\u5931\u8d25\u5219\u91cd\u590d\u6b65\u9aa42\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5b89\u5168\u6027\u95ee\u9898\n<ul>\n<li>Base64\u4ec5\u4e3a\u7f16\u7801\u800c\u975e\u52a0\u5bc6&#xff0c;\u51ed\u8bc1\u6613\u88ab\u89e3\u7801\u4e3a\u660e\u6587&#xff0c;\u9700\u914d\u5408HTTPS\u4fdd\u8bc1\u4f20\u8f93\u5b89\u5168\u3002<\/li>\n<li>\u65e0\u6cd5\u9632\u5fa1\u91cd\u653e\u653b\u51fb&#xff0c;\u653b\u51fb\u8005\u53ef\u622a\u83b7\u51ed\u8bc1\u540e\u91cd\u590d\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Base64\u7f16\u7801\u4f9d\u8d56 \u4f7f\u7528mbedtls\/base64.h\u5e93\u8fdb\u884c\u7f16\u7801&#xff0c;\u9700\u5728menuconfig\u4e2d\u542f\u7528MBEDTLS_BASE64_C\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>esp32 idf\u5b9e\u73b0\u7ec6\u8282:<\/p>\n<\/li>\n<p>\u5ba2\u6237\u7aef\u53d1\u9001\u8bf7\u6c42\u8bbf\u95ee\u53d7\u9650\u533a\u57df&#xff0c;\u670d\u52a1\u5668\u8fd4\u56de401\u672a\u6388\u6743&#xff0c;\u8981\u6c42\u8ba4\u8bc1\u3002\u5ba2\u6237\u7aef\u5c06\u7528\u6237\u540d\u548c\u5bc6\u7801\u62fc\u63a5\u6210\u201cusername:password\u201d\u683c\u5f0f&#xff0c;\u8fdb\u884cBase64\u7f16\u7801&#xff0c;\u7136\u540e\u653e\u5728Authorization\u5934\u7684Basic\u5b57\u6bb5\u4e2d\u53d1\u9001\u3002\u670d\u52a1\u5668\u89e3\u7801\u9a8c\u8bc1&#xff0c;\u901a\u8fc7\u5219\u8fd4\u56de\u8d44\u6e90\u3002<\/p>\n<p>\u5bf9\u4e8e\u670d\u52a1\u5668\u90e8\u5206&#xff0c;\u9700\u8981ESP-IDF\u7684httpd\u7ec4\u4ef6&#xff0c;\u521b\u5efaHTTP\u670d\u52a1\u5668\u3002\u5904\u7406\u51fd\u6570\u4e2d&#xff0c;\u68c0\u67e5\u8bf7\u6c42\u5934\u4e2d\u7684Authorization\u5b57\u6bb5&#xff0c;\u5982\u679c\u6ca1\u6709&#xff0c;\u53d1\u9001401&#xff0c;\u5e76\u8bbe\u7f6eWWW-Authenticate\u5934\u3002\u5982\u679c\u6709&#xff0c;\u89e3\u7801Base64&#xff0c;\u9a8c\u8bc1\u7528\u6237\u540d\u5bc6\u7801\u3002<\/p>\n<p>\u5bf9\u4e8e\u5ba2\u6237\u7aef\u90e8\u5206&#xff0c;\u4f7f\u7528esp_http_client\u7ec4\u4ef6\u3002\u5f53\u53d1\u8d77\u8bf7\u6c42\u65f6&#xff0c;\u5982\u679c\u670d\u52a1\u5668\u8fd4\u56de401&#xff0c;\u9700\u8981\u5904\u7406\u91cd\u8bd5&#xff0c;\u6216\u8005\u76f4\u63a5\u9884\u5148\u6dfb\u52a0Authorization\u5934\u3002\u81ea\u52a8\u5904\u7406401\u53ef\u80fd\u9700\u8981\u5ba2\u6237\u7aef\u81ea\u5df1\u5904\u7406&#xff0c;\u6216\u8005\u76f4\u63a5\u5728\u7b2c\u4e00\u6b21\u8bf7\u6c42\u65f6\u6dfb\u52a0Authorization\u5934&#xff0c;\u907f\u514d401\u54cd\u5e94\u3002<\/p>\n<p>\u8be6\u7ec6\u6b65\u9aa4&#xff1a;<\/p>\n<p>\u670d\u52a1\u5668\u5b9e\u73b0\u6b65\u9aa4&#xff1a;<\/p>\n<p>1. \u914d\u7f6e\u5e76\u542f\u52a8HTTP\u670d\u52a1\u5668\u3002<\/p>\n<p>2. \u6ce8\u518c\u5904\u7406\u7a0b\u5e8f&#xff0c;\u4f8b\u5982\u5904\u7406GET\u8bf7\u6c42\u5230\u67d0\u4e2aURI\u3002<\/p>\n<p>3. \u5728\u5904\u7406\u51fd\u6570\u4e2d&#xff0c;\u68c0\u67e5\u8bf7\u6c42\u5934\u7684Authorization\u5b57\u6bb5\u3002<\/p>\n<p>4. \u5982\u679c\u6ca1\u6709\u8be5\u5b57\u6bb5&#xff0c;\u8bbe\u7f6e\u54cd\u5e94\u72b6\u6001\u4e3a401&#xff0c;\u6dfb\u52a0WWW-Authenticate\u5934&#xff0c;\u8fd4\u56de\u3002<\/p>\n<p>5. \u5982\u679c\u6709&#xff0c;\u63d0\u53d6Basic\u540e\u9762\u7684\u51ed\u8bc1&#xff0c;\u8fdb\u884cBase64\u89e3\u7801\u3002<\/p>\n<p>6. \u62c6\u5206\u7528\u6237\u540d\u548c\u5bc6\u7801&#xff0c;\u4e0e\u9884\u8bbe\u7684\u8fdb\u884c\u6bd4\u8f83\u3002<\/p>\n<p>7. \u5982\u679c\u5339\u914d&#xff0c;\u8fd4\u56de\u8bf7\u6c42\u7684\u8d44\u6e90&#xff1b;\u5426\u5219\u8fd4\u56de403\u7981\u6b62\u8bbf\u95ee\u3002<\/p>\n<p>\u5ba2\u6237\u7aef\u5b9e\u73b0\u6b65\u9aa4&#xff1a;<\/p>\n<p>1. \u914d\u7f6eWiFi\u8fde\u63a5&#xff0c;\u8fde\u63a5\u5230AP\u3002<\/p>\n<p>2. \u4f7f\u7528esp_http_client\u53d1\u8d77HTTP GET\u8bf7\u6c42\u3002<\/p>\n<p>3. \u6784\u9020Authorization\u5934&#xff0c;\u5c06\u7528\u6237\u540d\u5bc6\u7801\u62fc\u63a5\u540eBase64\u7f16\u7801\u3002<\/p>\n<p>4. \u5c06\u5934\u6dfb\u52a0\u5230\u8bf7\u6c42\u4e2d&#xff0c;\u53d1\u9001\u8bf7\u6c42\u3002<\/p>\n<p>5. \u5904\u7406\u54cd\u5e94\u3002<\/p>\n<p>\u73b0\u5728&#xff0c;\u4ee3\u7801\u65b9\u9762\u9700\u8981\u6ce8\u610f\u7684\u70b9&#xff1a;<\/p>\n<p>\u670d\u52a1\u5668\u7aef&#xff1a;<\/p>\n<p>&#8211; \u4f7f\u7528httpd_config_t\u914d\u7f6e\u670d\u52a1\u5668\u53c2\u6570\u3002<\/p>\n<p>&#8211; \u521b\u5efaURI\u5904\u7406\u51fd\u6570&#xff0c;\u68c0\u67e5\u8bf7\u6c42\u5934\u3002<\/p>\n<p>&#8211; \u5904\u7406Base64\u89e3\u7801&#xff0c;\u7528\u6237\u5bc6\u7801\u6821\u9a8c\u3002<\/p>\n<p>&#8211; \u9700\u8981\u5305\u542b\u5fc5\u8981\u7684\u5934\u6587\u4ef6&#xff0c;\u6bd4\u5982httpd.h&#xff0c;\u4ee5\u53cabase64\u7f16\u89e3\u7801\u51fd\u6570\u3002<\/p>\n<p>\u5ba2\u6237\u7aef\u7aef&#xff1a;<\/p>\n<p>&#8211; \u4f7f\u7528esp_http_client_config_t\u914d\u7f6e\u5ba2\u6237\u7aef\u53c2\u6570\u3002<\/p>\n<p>&#8211; \u751f\u6210Authorization\u5934&#xff0c;\u5176\u4e2dBase64\u7f16\u7801\u9700\u8981\u6ce8\u610f\u662f\u5426\u6b63\u786e\u5904\u7406\u3002<\/p>\n<p>&#8211; \u53ef\u80fd\u9700\u8981\u624b\u52a8\u6dfb\u52a0\u5934\u5b57\u6bb5\u3002<\/p>\n<p>Base64\u7f16\u7801\u5728ESP32\u4e2d\u53ef\u4ee5\u7528mbedtls\u5e93\u4e2d\u7684\u51fd\u6570&#xff0c;\u6216\u8005\u4f7f\u7528\u5185\u7f6e\u7684base64\u7f16\u7801\u51fd\u6570\u3002\u4f8b\u5982&#xff0c;esp-idf\u6709\u63d0\u4f9bbase64_encode\u51fd\u6570\u5417,\u6216\u8005\u9700\u8981\u81ea\u5df1\u5b9e\u73b0,\u6216\u8005\u4f7f\u7528mbedtls\u7684base64\u51fd\u6570\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u4f7f\u7528mbedtls_base64_encode\u51fd\u6570\u6765\u7f16\u7801\u7528\u6237\u540d\u548c\u5bc6\u7801\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u6ce8\u610f&#xff0c;\u5728\u62fc\u63a5\u7528\u6237\u540d\u5bc6\u7801\u65f6&#xff0c;\u4e2d\u95f4\u7528\u5192\u53f7\u8fde\u63a5&#xff0c;\u4f8b\u5982&#034;admin:password&#034;&#xff0c;\u7136\u540eBase64\u7f16\u7801\u3002<\/p>\n<p>\u5728\u670d\u52a1\u5668\u7aef&#xff0c;\u6536\u5230Authorization\u5934\u540e&#xff0c;\u53d6\u51faBase64\u5b57\u7b26\u4e32&#xff0c;\u89e3\u7801\u5f97\u5230&#034;username:password&#034;&#xff0c;\u7136\u540e\u5206\u5272\u6bd4\u8f83\u3002<\/p>\n<h3>\u4e09.\u670d\u52a1\u5668\u4ee3\u7801<\/h3>\n<p>ESP32 IDF \u5b9e\u73b0\u670d\u52a1\u5668\u7aef\u4ee3\u7801\u00a0\u5b9e\u73b0\u4e00\u4e2a\u5e26\u6709 Basic \u8ba4\u8bc1\u7684 HTTP \u670d\u52a1\u5668\u3002<\/p>\n<p>#include &lt;string.h&gt;<br \/>\n#include &#034;freertos\/FreeRTOS.h&#034;<br \/>\n#include &#034;freertos\/task.h&#034;<br \/>\n#include &#034;esp_system.h&#034;<br \/>\n#include &#034;esp_wifi.h&#034;<br \/>\n#include &#034;esp_event.h&#034;<br \/>\n#include &#034;esp_log.h&#034;<br \/>\n#include &#034;nvs_flash.h&#034;<br \/>\n#include &#034;esp_http_server.h&#034;<br \/>\n#include &#034;mbedtls\/base64.h&#034;<\/p>\n<p>static const char *TAG &#061; &#034;http_server&#034;;<br \/>\n#define WIFI_SSID \u00a0 \u00a0 \u00a0&#034;YOUR_SSID&#034;<br \/>\n#define WIFI_PASS \u00a0 \u00a0 \u00a0&#034;YOUR_PASSWORD&#034;<\/p>\n<p>static httpd_handle_t server &#061; NULL;<\/p>\n<p>\/\/ Basic \u8ba4\u8bc1\u5904\u7406\u51fd\u6570<br \/>\nstatic esp_err_t basic_auth_handler(httpd_req_t *req) {<br \/>\n\u00a0 \u00a0 const char *auth_header &#061; httpd_req_get_hdr_value_str(req, &#034;Authorization&#034;);<br \/>\n\u00a0 \u00a0 if (!auth_header) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 httpd_resp_set_status(req, &#034;401 Unauthorized&#034;);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 httpd_resp_set_hdr(req, &#034;WWW-Authenticate&#034;, &#034;Basic realm&#061;\\\\&#034;Restricted Area\\\\&#034;&#034;);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 httpd_resp_send(req, &#034;Authentication Required&#034;, HTTPD_RESP_USE_STRLEN);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return ESP_OK;<br \/>\n\u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 if (strncmp(auth_header, &#034;Basic &#034;, 6) !&#061; 0) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, &#034;Invalid auth header&#034;);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return ESP_FAIL;<br \/>\n\u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 const char *encoded_creds &#061; auth_header &#043; 6;<br \/>\n\u00a0 \u00a0 uint8_t decoded_creds[128];<br \/>\n\u00a0 \u00a0 size_t out_len;<br \/>\n\u00a0 \u00a0 int ret &#061; mbedtls_base64_decode(decoded_creds, sizeof(decoded_creds), &amp;out_len,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0(const unsigned char *)encoded_creds, strlen(encoded_creds));<br \/>\n\u00a0 \u00a0 if (ret !&#061; 0) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, &#034;Base64 decode failed&#034;);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return ESP_FAIL;<br \/>\n\u00a0 \u00a0 }<br \/>\n\u00a0 \u00a0 decoded_creds[out_len] &#061; &#039;\\\\0&#039;;<\/p>\n<p>\u00a0 \u00a0 char *username &#061; strtok((char *)decoded_creds, &#034;:&#034;);<br \/>\n\u00a0 \u00a0 char *password &#061; strtok(NULL, &#034;:&#034;);<br \/>\n\u00a0 \u00a0 if (!username || !password) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, &#034;Invalid credentials&#034;);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return ESP_FAIL;<br \/>\n\u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 \/\/ \u9a8c\u8bc1\u7528\u6237\u540d\u5bc6\u7801&#xff08;\u793a\u4f8b\u4e3a admin\/password123&#xff09;<br \/>\n\u00a0 \u00a0 if (strcmp(username, &#034;admin&#034;) || strcmp(password, &#034;password123&#034;)) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, &#034;Invalid credentials&#034;);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return ESP_FAIL;<br \/>\n\u00a0 \u00a0 }<\/p>\n<p>\u00a0 \u00a0 httpd_resp_send(req, &#034;Authenticated Successfully!&#034;, HTTPD_RESP_USE_STRLEN);<br \/>\n\u00a0 \u00a0 return ESP_OK;<br \/>\n}<\/p>\n<p>\/\/ URI \u8def\u7531\u914d\u7f6e<br \/>\nstatic httpd_uri_t uri_handler &#061; {<br \/>\n\u00a0 \u00a0 .uri &#061; &#034;\/&#034;,<br \/>\n\u00a0 \u00a0 .method &#061; HTTP_GET,<br \/>\n\u00a0 \u00a0 .handler &#061; basic_auth_handler,<br \/>\n\u00a0 \u00a0 .user_ctx &#061; NULL<br \/>\n};<\/p>\n<p>\/\/ \u542f\u52a8 HTTP \u670d\u52a1\u5668<br \/>\nstatic void start_webserver() {<br \/>\n\u00a0 \u00a0 httpd_config_t config &#061; HTTPD_DEFAULT_CONFIG();<br \/>\n\u00a0 \u00a0 config.lru_purge_enable &#061; true;<\/p>\n<p>\u00a0 \u00a0 if (httpd_start(&amp;server, &amp;config) &#061;&#061; ESP_OK) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 httpd_register_uri_handler(server, &amp;uri_handler);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 ESP_LOGI(TAG, &#034;HTTP server started&#034;);<br \/>\n\u00a0 \u00a0 } else {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 ESP_LOGE(TAG, &#034;Failed to start server&#034;);<br \/>\n\u00a0 \u00a0 }<br \/>\n}<\/p>\n<p>\/\/ WiFi \u4e8b\u4ef6\u5904\u7406<br \/>\nstatic void wifi_event_handler(void *arg, esp_event_base_t event_base,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0int32_t event_id, void *event_data) {<br \/>\n\u00a0 \u00a0 if (event_id &#061;&#061; WIFI_EVENT_STA_START) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 esp_wifi_connect();<br \/>\n\u00a0 \u00a0 } else if (event_id &#061;&#061; IP_EVENT_STA_GOT_IP) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 start_webserver();<br \/>\n\u00a0 \u00a0 }<br \/>\n}<\/p>\n<p>\/\/ \u521d\u59cb\u5316 WiFi<br \/>\nstatic void wifi_init_sta() {<br \/>\n\u00a0 \u00a0 esp_netif_init();<br \/>\n\u00a0 \u00a0 esp_event_loop_create_default();<br \/>\n\u00a0 \u00a0 esp_netif_create_default_wifi_sta();<\/p>\n<p>\u00a0 \u00a0 wifi_init_config_t cfg &#061; WIFI_INIT_CONFIG_DEFAULT();<br \/>\n\u00a0 \u00a0 esp_wifi_init(&amp;cfg);<\/p>\n<p>\u00a0 \u00a0 esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &amp;wifi_event_handler, NULL);<br \/>\n\u00a0 \u00a0 esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &amp;wifi_event_handler, NULL);<\/p>\n<p>\u00a0 \u00a0 wifi_config_t wifi_config &#061; {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 .sta &#061; {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .ssid &#061; WIFI_SSID,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .password &#061; WIFI_PASS,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .threshold.authmode &#061; WIFI_AUTH_WPA2_PSK<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 }<br \/>\n\u00a0 \u00a0 };<br \/>\n\u00a0 \u00a0 esp_wifi_set_mode(WIFI_MODE_STA);<br \/>\n\u00a0 \u00a0 esp_wifi_set_config(WIFI_IF_STA, &amp;wifi_config);<br \/>\n\u00a0 \u00a0 esp_wifi_start();<br \/>\n}<\/p>\n<p>void app_main() {<br \/>\n\u00a0 \u00a0 nvs_flash_init();<br \/>\n\u00a0 \u00a0 wifi_init_sta();<br \/>\n} <\/p>\n<p>\u56db.\u5ba2\u6237\u7aef\u4ee3\u7801<\/p>\n<p>\u5b9e\u73b0\u4e00\u4e2a\u901a\u8fc7 Basic \u8ba4\u8bc1\u8bbf\u95ee\u670d\u52a1\u5668\u7684\u5ba2\u6237\u7aef\u3002<\/p>\n<p>#include &lt;string.h&gt;<br \/>\n#include &#034;freertos\/FreeRTOS.h&#034;<br \/>\n#include &#034;freertos\/task.h&#034;<br \/>\n#include &#034;esp_system.h&#034;<br \/>\n#include &#034;esp_wifi.h&#034;<br \/>\n#include &#034;esp_event.h&#034;<br \/>\n#include &#034;esp_log.h&#034;<br \/>\n#include &#034;nvs_flash.h&#034;<br \/>\n#include &#034;esp_http_client.h&#034;<br \/>\n#include &#034;mbedtls\/base64.h&#034;<\/p>\n<p>static const char *TAG &#061; &#034;http_client&#034;;<br \/>\n#define WIFI_SSID \u00a0 \u00a0 \u00a0&#034;YOUR_SSID&#034;<br \/>\n#define WIFI_PASS \u00a0 \u00a0 \u00a0&#034;YOUR_PASSWORD&#034;<br \/>\n#define SERVER_URL \u00a0 \u00a0 &#034;http:\/\/SERVER_IP\/&#034;<\/p>\n<p>\/\/ HTTP \u5ba2\u6237\u7aef\u4efb\u52a1<br \/>\nstatic void http_client_task(void *pvParameters) {<br \/>\n\u00a0 \u00a0 const char *username &#061; &#034;admin&#034;;<br \/>\n\u00a0 \u00a0 const char *password &#061; &#034;password123&#034;;<br \/>\n\u00a0 \u00a0 char credentials[64];<br \/>\n\u00a0 \u00a0 snprintf(credentials, sizeof(credentials), &#034;%s:%s&#034;, username, password);<\/p>\n<p>\u00a0 \u00a0 unsigned char encoded_creds[128];<br \/>\n\u00a0 \u00a0 size_t encoded_len;<br \/>\n\u00a0 \u00a0 int ret &#061; mbedtls_base64_encode(encoded_creds, sizeof(encoded_creds), &amp;encoded_len,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0(const unsigned char *)credentials, strlen(credentials));<br \/>\n\u00a0 \u00a0 if (ret !&#061; 0) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 ESP_LOGE(TAG, &#034;Base64 encode failed: %d&#034;, ret);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 vTaskDelete(NULL);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 return;<br \/>\n\u00a0 \u00a0 }<br \/>\n\u00a0 \u00a0 encoded_creds[encoded_len] &#061; &#039;\\\\0&#039;;<\/p>\n<p>\u00a0 \u00a0 char auth_header[128];<br \/>\n\u00a0 \u00a0 snprintf(auth_header, sizeof(auth_header), &#034;Basic %s&#034;, encoded_creds);<\/p>\n<p>\u00a0 \u00a0 esp_http_client_config_t config &#061; {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 .url &#061; SERVER_URL,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 .method &#061; HTTP_METHOD_GET,<br \/>\n\u00a0 \u00a0 };<br \/>\n\u00a0 \u00a0 esp_http_client_handle_t client &#061; esp_http_client_init(&amp;config);<br \/>\n\u00a0 \u00a0 esp_http_client_set_header(client, &#034;Authorization&#034;, auth_header);<\/p>\n<p>\u00a0 \u00a0 esp_err_t err &#061; esp_http_client_perform(client);<br \/>\n\u00a0 \u00a0 if (err &#061;&#061; ESP_OK) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 ESP_LOGI(TAG, &#034;Status &#061; %d, Content Length &#061; %d&#034;,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0esp_http_client_get_status_code(client),<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0esp_http_client_get_content_length(client));<br \/>\n\u00a0 \u00a0 } else {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 ESP_LOGE(TAG, &#034;Request failed: %s&#034;, esp_err_to_name(err));<br \/>\n\u00a0 \u00a0 }<br \/>\n\u00a0 \u00a0 esp_http_client_cleanup(client);<br \/>\n\u00a0 \u00a0 vTaskDelete(NULL);<br \/>\n}<\/p>\n<p>\/\/ WiFi \u4e8b\u4ef6\u5904\u7406<br \/>\nstatic void wifi_event_handler(void *arg, esp_event_base_t event_base,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0int32_t event_id, void *event_data) {<br \/>\n\u00a0 \u00a0 if (event_id &#061;&#061; WIFI_EVENT_STA_START) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 esp_wifi_connect();<br \/>\n\u00a0 \u00a0 } else if (event_id &#061;&#061; IP_EVENT_STA_GOT_IP) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 xTaskCreate(http_client_task, &#034;http_client_task&#034;, 4096, NULL, 5, NULL);<br \/>\n\u00a0 \u00a0 }<br \/>\n}<\/p>\n<p>\/\/ \u521d\u59cb\u5316 WiFi<br \/>\nstatic void wifi_init_sta() {<br \/>\n\u00a0 \u00a0 esp_netif_init();<br \/>\n\u00a0 \u00a0 esp_event_loop_create_default();<br \/>\n\u00a0 \u00a0 esp_netif_create_default_wifi_sta();<\/p>\n<p>\u00a0 \u00a0 wifi_init_config_t cfg &#061; WIFI_INIT_CONFIG_DEFAULT();<br \/>\n\u00a0 \u00a0 esp_wifi_init(&amp;cfg);<\/p>\n<p>\u00a0 \u00a0 esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &amp;wifi_event_handler, NULL);<br \/>\n\u00a0 \u00a0 esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &amp;wifi_event_handler, NULL);<\/p>\n<p>\u00a0 \u00a0 wifi_config_t wifi_config &#061; {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 .sta &#061; {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .ssid &#061; WIFI_SSID,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .password &#061; WIFI_PASS,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .threshold.authmode &#061; WIFI_AUTH_WPA2_PSK<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 }<br \/>\n\u00a0 \u00a0 };<br \/>\n\u00a0 \u00a0 esp_wifi_set_mode(WIFI_MODE_STA);<br \/>\n\u00a0 \u00a0 esp_wifi_set_config(WIFI_IF_STA, &amp;wifi_config);<br \/>\n\u00a0 \u00a0 esp_wifi_start();<br \/>\n}<\/p>\n<p>void app_main() {<br \/>\n\u00a0 \u00a0 nvs_flash_init();<br \/>\n\u00a0 \u00a0 wifi_init_sta();<br \/>\n} <\/p>\n<h4>\u8bf4\u660e<\/h4>\n<li>\n<p>\u914d\u7f6e WiFi \u4fe1\u606f \u66ff\u6362\u4ee3\u7801\u4e2d\u7684\u00a0YOUR_SSID\u3001YOUR_PASSWORD\u00a0\u548c\u00a0SERVER_IP\u3002<\/p>\n<\/li>\n<li>\n<p>\u90e8\u7f72\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef<\/p>\n<ul>\n<li>\n<p>\u670d\u52a1\u5668\u4ee3\u7801&#xff1a;\u8fd0\u884c\u5728\u63d0\u4f9b\u8d44\u6e90\u7684 ESP32 \u4e0a\u3002<\/p>\n<\/li>\n<li>\n<p>\u5ba2\u6237\u7aef\u4ee3\u7801&#xff1a;\u8fd0\u884c\u5728\u9700\u8981\u8bbf\u95ee\u8d44\u6e90\u7684 ESP32 \u4e0a\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9a8c\u8bc1\u6d41\u7a0b<\/p>\n<ul>\n<li>\n<p>\u5ba2\u6237\u7aef\u9996\u6b21\u8bf7\u6c42\u4f1a\u6536\u5230\u00a0401&#xff0c;\u968f\u540e\u643a\u5e26\u8ba4\u8bc1\u5934\u91cd\u65b0\u8bf7\u6c42\u3002<\/p>\n<\/li>\n<li>\n<p>\u670d\u52a1\u5668\u9a8c\u8bc1\u901a\u8fc7\u540e\u8fd4\u56de\u8d44\u6e90&#xff0c;\u5426\u5219\u8fd4\u56de\u00a0403\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801&#xff0c;ESP32 \u53ef\u5b9e\u73b0\u5b8c\u6574\u7684 HTTP \u57fa\u672c\u8ba4\u8bc1\u6d41\u7a0b&#xff0c;\u9002\u7528\u4e8e IoT \u8bbe\u5907\u7684\u5b89\u5168\u901a\u4fe1\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb824\u6b21\uff0c\u70b9\u8d5e38\u6b21\uff0c\u6536\u85cf10\u6b21\u3002Base64\u662f\u4e00\u79cd\u5c06\u4e8c\u8fdb\u5236\u6570\u636e\u8f6c\u6362\u4e3a ASCII \u5b57\u7b26\u4e32\u7684\u7f16\u7801\u65b9\u5f0f\uff0c\u4f7f\u7528 64 \u4e2a\u53ef\u6253\u5370\u5b57\u7b26\uff08\uff09\u8868\u793a\u4e8c\u8fdb\u5236\u5185\u5bb9\uff0c\u5e76\u5728\u672b\u5c3e\u7528\u586b\u5145\u3002\u5176\u6838\u5fc3\u76ee\u7684\u662f\u89e3\u51b3\u4e8c\u8fdb\u5236\u6570\u636e\u5728\u7eaf\u6587\u672c\u534f\u8bae\uff08\u5982 HTTP\uff09\u4e2d\u4f20\u8f93\u65f6\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09 \u4f5c\u7528\uff1a\u5c06\u7528\u6237\u540d\u548c\u5bc6\u7801\u62fc\u63a5\u4e3a username:password \u683c\u5f0f\u540e Base64 \u7f16\u7801\uff0c\u7f6e\u4e8e Authorization: Basic  \u5934\u4e2d\u4f20\u8f93\u3002\u4f8b\u5982:Base64\u4f18\u52bf\u6587\u672c\u534f\u8bae\u517c\u5bb9\u6027\u3002<\/p>\n","protected":false},"author":2,"featured_media":20248,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[151,43,191],"topic":[],"class_list":["post-20249","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-http","tag-43","tag-191"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>(\u4e00)HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09\u539f\u7406\u8fc7\u7a0b,\u4ee5\u53caesp32 idf\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4f8b\u7a0b - \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\/20249.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"(\u4e00)HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09\u539f\u7406\u8fc7\u7a0b,\u4ee5\u53caesp32 idf\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4f8b\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb824\u6b21\uff0c\u70b9\u8d5e38\u6b21\uff0c\u6536\u85cf10\u6b21\u3002Base64\u662f\u4e00\u79cd\u5c06\u4e8c\u8fdb\u5236\u6570\u636e\u8f6c\u6362\u4e3a ASCII \u5b57\u7b26\u4e32\u7684\u7f16\u7801\u65b9\u5f0f\uff0c\u4f7f\u7528 64 \u4e2a\u53ef\u6253\u5370\u5b57\u7b26\uff08\uff09\u8868\u793a\u4e8c\u8fdb\u5236\u5185\u5bb9\uff0c\u5e76\u5728\u672b\u5c3e\u7528\u586b\u5145\u3002\u5176\u6838\u5fc3\u76ee\u7684\u662f\u89e3\u51b3\u4e8c\u8fdb\u5236\u6570\u636e\u5728\u7eaf\u6587\u672c\u534f\u8bae\uff08\u5982 HTTP\uff09\u4e2d\u4f20\u8f93\u65f6\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09 \u4f5c\u7528\uff1a\u5c06\u7528\u6237\u540d\u548c\u5bc6\u7801\u62fc\u63a5\u4e3a username:password \u683c\u5f0f\u540e Base64 \u7f16\u7801\uff0c\u7f6e\u4e8e Authorization: Basic \u5934\u4e2d\u4f20\u8f93\u3002\u4f8b\u5982:Base64\u4f18\u52bf\u6587\u672c\u534f\u8bae\u517c\u5bb9\u6027\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/20249.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-18T18:59:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418185906-6802a0faeb640.jpg\" \/>\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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/20249.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/20249.html\",\"name\":\"(\u4e00)HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09\u539f\u7406\u8fc7\u7a0b,\u4ee5\u53caesp32 idf\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4f8b\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T18:59:08+00:00\",\"dateModified\":\"2025-04-18T18:59:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/20249.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/20249.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/20249.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"(\u4e00)HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09\u539f\u7406\u8fc7\u7a0b,\u4ee5\u53caesp32 idf\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4f8b\u7a0b\"}]},{\"@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":"(\u4e00)HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09\u539f\u7406\u8fc7\u7a0b,\u4ee5\u53caesp32 idf\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4f8b\u7a0b - \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\/20249.html","og_locale":"zh_CN","og_type":"article","og_title":"(\u4e00)HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09\u539f\u7406\u8fc7\u7a0b,\u4ee5\u53caesp32 idf\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4f8b\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb824\u6b21\uff0c\u70b9\u8d5e38\u6b21\uff0c\u6536\u85cf10\u6b21\u3002Base64\u662f\u4e00\u79cd\u5c06\u4e8c\u8fdb\u5236\u6570\u636e\u8f6c\u6362\u4e3a ASCII \u5b57\u7b26\u4e32\u7684\u7f16\u7801\u65b9\u5f0f\uff0c\u4f7f\u7528 64 \u4e2a\u53ef\u6253\u5370\u5b57\u7b26\uff08\uff09\u8868\u793a\u4e8c\u8fdb\u5236\u5185\u5bb9\uff0c\u5e76\u5728\u672b\u5c3e\u7528\u586b\u5145\u3002\u5176\u6838\u5fc3\u76ee\u7684\u662f\u89e3\u51b3\u4e8c\u8fdb\u5236\u6570\u636e\u5728\u7eaf\u6587\u672c\u534f\u8bae\uff08\u5982 HTTP\uff09\u4e2d\u4f20\u8f93\u65f6\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09 \u4f5c\u7528\uff1a\u5c06\u7528\u6237\u540d\u548c\u5bc6\u7801\u62fc\u63a5\u4e3a username:password \u683c\u5f0f\u540e Base64 \u7f16\u7801\uff0c\u7f6e\u4e8e Authorization: Basic \u5934\u4e2d\u4f20\u8f93\u3002\u4f8b\u5982:Base64\u4f18\u52bf\u6587\u672c\u534f\u8bae\u517c\u5bb9\u6027\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/20249.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T18:59:08+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418185906-6802a0faeb640.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/20249.html","url":"https:\/\/www.wsisp.com\/helps\/20249.html","name":"(\u4e00)HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09\u539f\u7406\u8fc7\u7a0b,\u4ee5\u53caesp32 idf\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4f8b\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T18:59:08+00:00","dateModified":"2025-04-18T18:59:08+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/20249.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/20249.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/20249.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"(\u4e00)HTTP \u57fa\u672c\u8ba4\u8bc1\uff08Basic Authentication\uff09\u539f\u7406\u8fc7\u7a0b,\u4ee5\u53caesp32 idf\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4f8b\u7a0b"}]},{"@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\/20249","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=20249"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/20249\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/20248"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=20249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=20249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=20249"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=20249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}