{"id":80758,"date":"2026-03-05T22:44:16","date_gmt":"2026-03-05T14:44:16","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/80758.html"},"modified":"2026-03-05T22:44:16","modified_gmt":"2026-03-05T14:44:16","slug":"%e5%9f%ba%e4%ba%8ec%e8%af%ad%e8%a8%80%e5%92%8chttp-api%e7%9a%84%e5%a4%a9%e6%b0%94%e6%9f%a5%e8%af%a2%e5%ae%a2%e6%88%b7%e7%ab%af%e5%ae%9e%e7%8e%b0%e4%b8%8e%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/80758.html","title":{"rendered":"\u57fa\u4e8eC\u8bed\u8a00\u548cHTTP API\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e0e\u5206\u6790"},"content":{"rendered":"<h3>\u5f15\u8a00<\/h3>\n<p>\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u6216\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u4e2d&#xff0c;\u901a\u8fc7Socket\u7f16\u7a0b\u4e0eWeb API\u4ea4\u4e92\u662f\u4e00\u9879\u57fa\u7840\u800c\u91cd\u8981\u7684\u6280\u80fd\u3002\u672c\u6587\u57fa\u4e8e\u4e00\u6bb5\u5b9e\u9645\u7f16\u5199\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u4ee3\u7801&#xff0c;\u8be6\u7ec6\u5206\u6790\u5176\u5b9e\u73b0\u539f\u7406\u3001\u6280\u672f\u8981\u70b9&#xff0c;\u5e76\u63a2\u8ba8\u5176\u4e2d\u5b58\u5728\u7684\u95ee\u9898\u4e0e\u4f18\u5316\u65b9\u5411\u3002\u8be5\u5ba2\u6237\u7aef\u901a\u8fc7TCP\u8fde\u63a5\u5411\u8fdc\u7a0b\u670d\u52a1\u5668\u53d1\u9001HTTP\u8bf7\u6c42&#xff0c;\u83b7\u53d6JSON\u683c\u5f0f\u7684\u5929\u6c14\u6570\u636e&#xff0c;\u5e76\u901a\u8fc7\u5b57\u7b26\u4e32\u64cd\u4f5c\u63d0\u53d6\u5173\u952e\u4fe1\u606f\u6253\u5370\u663e\u793a\u3002<\/p>\n<h3>\u6d89\u53ca\u7684\u6280\u672f\u70b9<\/h3>\n<li>\n<p>Socket\u7f51\u7edc\u7f16\u7a0b&#xff1a;\u521b\u5efaTCP\u5957\u63a5\u5b57&#xff0c;\u8fde\u63a5\u5230\u6307\u5b9aIP\u548c\u7aef\u53e3\u3002<\/p>\n<\/li>\n<li>\n<p>HTTP\u534f\u8bae&#xff1a;\u6784\u9020HTTP GET\u8bf7\u6c42&#xff0c;\u89e3\u6790\u54cd\u5e94&#xff08;\u542b\u72b6\u6001\u884c\u3001\u5934\u90e8\u548c\u5b9e\u4f53&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b57\u7b26\u4e32\u5904\u7406&#xff1a;\u4f7f\u7528strstr\u5b9a\u4f4dJSON\u5b57\u6bb5&#xff0c;\u5e76\u901a\u8fc7\u6307\u9488\u4fee\u6539\u5b57\u7b26\u4e32\u4ee5\u63d0\u53d6\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>JSON\u6570\u636e\u683c\u5f0f&#xff1a;\u670d\u52a1\u5668\u8fd4\u56de\u7684\u6570\u636e\u4e3aJSON&#xff0c;\u4f46\u5ba2\u6237\u7aef\u5e76\u672a\u4f7f\u7528JSON\u89e3\u6790\u5e93\u3002<\/p>\n<\/li>\n<li>\n<p>\u6807\u51c6I\/O\u4e0e\u9519\u8bef\u5904\u7406&#xff1a;printf\u8f93\u51fa&#xff0c;perror\u62a5\u544a\u9519\u8bef\u3002<\/p>\n<\/li>\n<li>\n<p>\u6f5c\u5728\u5b89\u5168\u95ee\u9898&#xff1a;\u4f7f\u7528gets\u8bfb\u53d6\u7528\u6237\u8f93\u5165&#xff0c;\u5b58\u5728\u7f13\u51b2\u533a\u6ea2\u51fa\u98ce\u9669\u3002<\/p>\n<\/li>\n<h3>\u7a0b\u5e8f\u6574\u4f53\u6846\u67b6<\/h3>\n<p>\u7a0b\u5e8f\u4e3b\u8981\u5206\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u6a21\u5757&#xff1a;<\/p>\n<ul>\n<li>\n<p>TCP\u8fde\u63a5\u5efa\u7acb&#xff1a;CreatTcpConnect\u51fd\u6570\u5c01\u88c5\u4e86socket\u3001connect\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<li>\n<p>HTTP\u8bf7\u6c42\u53d1\u9001&#xff1a;SendHttpRequest\u6784\u9020\u5e76\u53d1\u9001HTTP GET\u8bf7\u6c42\u3002<\/p>\n<\/li>\n<li>\n<p>HTTP\u54cd\u5e94\u63a5\u6536&#xff1a;RecvHttpRespone\u63a5\u6536\u670d\u52a1\u5668\u8fd4\u56de\u7684\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u89e3\u6790\u4e0e\u6253\u5370&#xff1a;PrintfCurWeather\u548cPrintfFigWeather\u901a\u8fc7\u5b57\u7b26\u4e32\u64cd\u4f5c\u4ece\u54cd\u5e94\u4f53\u4e2d\u63d0\u53d6\u5929\u6c14\u4fe1\u606f\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e3b\u51fd\u6570\u6d41\u7a0b&#xff1a;<\/p>\n<li>\n<p>\u63d0\u793a\u7528\u6237\u8f93\u5165\u57ce\u5e02\u540d&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6784\u9020\u5f53\u524d\u5929\u6c14API\u7684URL&#xff0c;\u5efa\u7acbTCP\u8fde\u63a5&#xff0c;\u53d1\u9001\u8bf7\u6c42&#xff0c;\u63a5\u6536\u54cd\u5e94&#xff0c;\u5173\u95ed\u8fde\u63a5&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6784\u9020\u672a\u6765\u5929\u6c14API\u7684URL&#xff0c;\u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u8c03\u7528\u4e24\u4e2a\u6253\u5370\u51fd\u6570\u5206\u522b\u89e3\u6790\u5e76\u663e\u793a\u5929\u6c14\u4fe1\u606f\u3002<\/p>\n<\/li>\n<\/li>\n<\/ul>\n<h3 style=\"background-color:transparent\">\u4ee3\u7801\u8be6\u7ec6\u5206\u6790<\/h3>\n<h4>1. TCP\u8fde\u63a5\u521b\u5efa<\/h4>\n<p>c<\/p>\n<p>int CreatTcpConnect(char *pserip, int port)<br \/>\n{<br \/>\n    int sockfd &#061; socket(AF_INET, SOCK_STREAM, 0);<br \/>\n    struct sockaddr_in serveaddr;<br \/>\n    serveaddr.sin_family &#061; AF_INET;<br \/>\n    serveaddr.sin_port &#061; htons(port);<br \/>\n    serveaddr.sin_addr.s_addr &#061; inet_addr(pserip);<br \/>\n    connect(sockfd, (struct sockaddr *)&amp;serveaddr, sizeof(serveaddr));<br \/>\n    return sockfd;<br \/>\n}<\/p>\n<p>\u8be5\u51fd\u6570\u521b\u5efaTCP\u5957\u63a5\u5b57\u5e76\u8fde\u63a5\u5230\u6307\u5b9a\u670d\u52a1\u5668\u3002\u4f7f\u7528\u4e86IPv4\u3001\u6d41\u5f0f\u5957\u63a5\u5b57\u3002\u8bb0\u5f97\u5bf9socket\u548cconnect\u8fd4\u56de\u503c\u505a\u5b8c\u6574\u9519\u8bef\u5904\u7406&#xff08;\u539f\u4ee3\u7801\u4e2d\u6709\u68c0\u67e5&#xff0c;\u4f46\u8fd9\u91cc\u7b80\u5316\u63cf\u8ff0&#xff09;\u3002inet_addr\u5c06\u70b9\u5206\u5341\u8fdb\u5236IP\u8f6c\u6362\u4e3a\u7f51\u7edc\u5b57\u8282\u5e8f\u7684\u6574\u6570\u3002<\/p>\n<h4>2. HTTP\u8bf7\u6c42\u6784\u9020<\/h4>\n<p>c<\/p>\n<p>int SendHttpRequest(int sockfd, char *purl)<br \/>\n{<br \/>\n    char tmpbuff[4096] &#061; {0};<br \/>\n    sprintf(tmpbuff, &#034;GET %s HTTP\/1.1\\\\r\\\\n&#034;, purl);<br \/>\n    sprintf(tmpbuff, &#034;%sHost: api.k780.com\\\\r\\\\n&#034;, tmpbuff);<br \/>\n    \/\/ &#8230; \u6dfb\u52a0\u5176\u4ed6\u5934\u90e8<br \/>\n    send(sockfd, tmpbuff, strlen(tmpbuff), 0);<br \/>\n}<\/p>\n<p>\u901a\u8fc7\u591a\u6b21sprintf\u62fc\u63a5HTTP\u8bf7\u6c42&#xff0c;\u6ce8\u610f\u8fd9\u91cc\u4f7f\u7528\u4e86tmpbuff\u4f5c\u4e3a\u6e90\u548c\u76ee\u6807&#xff0c;\u867d\u7136\u80fd\u5de5\u4f5c&#xff0c;\u4f46\u5b58\u5728\u7f13\u51b2\u533a\u91cd\u53e0\u7684\u98ce\u9669\u3002\u8bf7\u6c42\u5305\u542b\u4e86\u5fc5\u8981\u7684\u5934\u90e8&#xff08;Host\u3001User-Agent\u3001Accept\u7b49&#xff09;\u3002<\/p>\n<h4>3. \u54cd\u5e94\u63a5\u6536<\/h4>\n<p>c<\/p>\n<p>int RecvHttpRespone(int sockfd, char *ptmpbuff, int maxlen)<br \/>\n{<br \/>\n    recv(sockfd, ptmpbuff, maxlen, 0);<br \/>\n}<\/p>\n<p>\u7b80\u5355\u8c03\u7528recv\u4e00\u6b21\u63a5\u6536\u6570\u636e&#xff0c;\u672a\u8003\u8651\u6570\u636e\u53ef\u80fd\u5206\u591a\u6b21\u5230\u8fbe&#xff0c;\u4e5f\u672a\u5904\u7406\u7c98\u5305\u95ee\u9898\u3002\u5b9e\u9645\u7f51\u7edc\u4f20\u8f93\u4e2d&#xff0c;HTTP\u54cd\u5e94\u53ef\u80fd\u8d85\u8fc7\u4e00\u6b21recv\u7684\u5927\u5c0f&#xff0c;\u4e14\u9700\u8981\u89e3\u6790\u5934\u90e8\u627e\u5230\u5185\u5bb9\u957f\u5ea6\u3002<\/p>\n<h4>4. \u6570\u636e\u89e3\u6790&#xff08;\u6838\u5fc3\u95ee\u9898&#xff09;<\/h4>\n<p>\u89e3\u6790\u51fd\u6570\u91c7\u7528\u4e86\u4e00\u79cd\u6781\u5176\u8106\u5f31\u7684\u5b57\u7b26\u4e32\u5904\u7406\u65b9\u5f0f&#xff1a;\u901a\u8fc7strstr\u67e5\u627e\u7279\u5b9a\u5b57\u6bb5\u540d&#xff0c;\u7136\u540e\u624b\u52a8\u4fee\u6539\u6307\u9488\u4f4d\u7f6e\u5e76\u63d2\u5165\u5b57\u7b26\u4e32\u7ed3\u675f\u7b26&#xff0c;\u4ece\u800c\u201c\u63d0\u53d6\u201d\u5b57\u6bb5\u503c\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>c<\/p>\n<p>phead &#061; strstr(ptmp_cur, &#034;days&#034;);<br \/>\nphead -&#061; 1;<br \/>\nptail &#061; strstr(ptmp_cur, &#034;week&#034;);<br \/>\nptail -&#061; 2;<br \/>\n*ptail &#061; &#039;\\\\0&#039;;<br \/>\nprintf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>\u8fd9\u79cd\u505a\u6cd5\u4f9d\u8d56\u4e8e\u670d\u52a1\u5668\u8fd4\u56de\u7684JSON\u683c\u5f0f\u4e25\u683c\u56fa\u5b9a&#xff0c;\u4e14\u5b57\u6bb5\u987a\u5e8f\u4e0d\u53d8\u3002\u4f46\u5b9e\u9645\u4e0a&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5982\u679cJSON\u5b57\u6bb5\u503c\u4e2d\u5305\u542b\u76ee\u6807\u5b57\u6bb5\u540d&#xff08;\u5982&#034;days&#034;\u51fa\u73b0\u5728\u503c\u4e2d&#xff09;&#xff0c;\u4f1a\u5bfc\u81f4\u9519\u8bef\u5b9a\u4f4d\u3002<\/p>\n<\/li>\n<li>\n<p>\u6307\u9488\u5411\u524d\u79fb\u52a8&#xff08;-1\u3001-2&#xff09;\u53ef\u80fd\u8d8a\u754c\u8bbf\u95ee&#xff0c;\u5f15\u53d1\u672a\u5b9a\u4e49\u884c\u4e3a\u3002<\/p>\n<\/li>\n<li>\n<p>\u76f4\u63a5\u4fee\u6539\u539f\u59cb\u7f13\u51b2\u533a\u7834\u574f\u4e86\u6570\u636e&#xff0c;\u540e\u7eed\u89e3\u6790\u53ef\u80fd\u51fa\u9519\u3002<\/p>\n<\/li>\n<li>\n<p>\u672a\u5bf9strstr\u8fd4\u56deNULL\u505a\u5904\u7406&#xff0c;\u82e5\u5b57\u6bb5\u7f3a\u5931\u5219\u7a0b\u5e8f\u5d29\u6e83\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u66f4\u597d\u7684\u505a\u6cd5\u662f\u4f7f\u7528JSON\u89e3\u6790\u5e93&#xff08;\u5982cJSON&#xff09;&#xff0c;\u4f46\u4ee3\u7801\u4e2d\u867d\u7136\u5305\u542b\u4e86cJSON.h&#xff0c;\u5374\u5e76\u672a\u4f7f\u7528\u3002<\/p>\n<h4>5. \u7528\u6237\u8f93\u5165<\/h4>\n<p>c<\/p>\n<p>char city[32] &#061; {0};<br \/>\ngets(city);<\/p>\n<p>gets\u662fC11\u6807\u51c6\u5df2\u5e9f\u5f03\u7684\u51fd\u6570&#xff0c;\u56e0\u4e3a\u5b83\u65e0\u6cd5\u9650\u5236\u8f93\u5165\u957f\u5ea6&#xff0c;\u5f53\u7528\u6237\u8f93\u5165\u8d85\u8fc731\u4e2a\u5b57\u7b26\u65f6\u4f1a\u9020\u6210\u7f13\u51b2\u533a\u6ea2\u51fa&#xff0c;\u8986\u76d6\u6808\u4e0a\u5176\u4ed6\u6570\u636e&#xff0c;\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u6216\u88ab\u5229\u7528\u3002\u5e94\u6539\u7528fgets\u3002<\/p>\n<h4>6. \u786c\u7f16\u7801\u95ee\u9898<\/h4>\n<p>\u670d\u52a1\u5668IP\u5730\u5740&#xff08;103.205.5.206&#xff09;\u548c\u7aef\u53e3&#xff08;80&#xff09;\u76f4\u63a5\u5199\u5728\u4ee3\u7801\u4e2d&#xff0c;API\u7684\u57df\u540d&#xff08;api.k780.com&#xff09;\u4e5f\u786c\u7f16\u7801\u5728Host\u5934\u90e8\u3002\u82e5\u670d\u52a1\u5668\u53d8\u66f4IP\u6216\u57df\u540d&#xff0c;\u9700\u8981\u91cd\u65b0\u7f16\u8bd1\u3002\u5efa\u8bae\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u6216\u547d\u4ee4\u884c\u53c2\u6570\u4f20\u5165\u3002<\/p>\n<h3>\u7a0b\u5e8f\u6d41\u7a0b\u56fe<\/h3>\n<p>text<\/p>\n<p>&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n|  \u8f93\u5165\u57ce\u5e02\u540d       |<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n          |<br \/>\n          v<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n| \u6784\u5efa\u5f53\u524d\u5929\u6c14URL   |<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n          |<br \/>\n          v<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n| \u5efa\u7acbTCP\u8fde\u63a5       |<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n          |<br \/>\n          v<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n| \u53d1\u9001HTTP\u8bf7\u6c42      |<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n          |<br \/>\n          v<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n| \u63a5\u6536\u54cd\u5e94          |<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n          |<br \/>\n          v<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n| \u5173\u95ed\u8fde\u63a5          |<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n          |<br \/>\n          v (\u91cd\u590d\u4e0a\u8ff0\u6b65\u9aa4\u83b7\u53d6\u672a\u6765\u5929\u6c14)<br \/>\n          |<br \/>\n          v<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n| \u89e3\u6790\u5e76\u6253\u5370\u5f53\u524d\u5929\u6c14|<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n          |<br \/>\n          v<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n| \u89e3\u6790\u5e76\u6253\u5370\u672a\u6765\u5929\u6c14|<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<\/p>\n<h3>\u5b58\u5728\u7684\u95ee\u9898\u4e0e\u4f18\u5316\u5efa\u8bae<\/h3>\n<h4>1. \u5b89\u5168\u6027\u95ee\u9898<\/h4>\n<ul>\n<li>\n<p>\u7f13\u51b2\u533a\u6ea2\u51fa&#xff1a;gets\u5fc5\u987b\u66ff\u6362\u4e3afgets(city, sizeof(city), stdin)\u5e76\u5904\u7406\u6362\u884c\u7b26\u3002<\/p>\n<\/li>\n<li>\n<p>\u6307\u9488\u8d8a\u754c&#xff1a;phead -&#061; 1\u3001ptail -&#061; 2\u7b49\u64cd\u4f5c\u5e94\u68c0\u67e5\u6307\u9488\u662f\u5426\u4ecd\u5728\u6709\u6548\u8303\u56f4\u5185&#xff0c;\u907f\u514d\u8bbf\u95ee\u975e\u6cd5\u5185\u5b58\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>2. \u7f51\u7edc\u901a\u4fe1\u53ef\u9760\u6027<\/h4>\n<ul>\n<li>\n<p>TCP\u7c98\u5305\u4e0e\u5206\u6bb5&#xff1a;recv\u4e00\u6b21\u53ef\u80fd\u63a5\u6536\u4e0d\u5168&#xff0c;\u5e94\u5faa\u73af\u63a5\u6536\u76f4\u5230\u8bfb\u53d6\u5b8c\u6574HTTP\u54cd\u5e94\u3002\u53ef\u4ee5\u901a\u8fc7\u89e3\u6790\u54cd\u5e94\u5934\u4e2d\u7684Content-Length\u5b57\u6bb5\u6216\u9047\u5230\\\\r\\\\n\\\\r\\\\n\u540e\u7ee7\u7eed\u8bfb\u53d6\u6307\u5b9a\u957f\u5ea6\u3002<\/p>\n<\/li>\n<li>\n<p>\u9519\u8bef\u5904\u7406&#xff1a;send\u548crecv\u8fd4\u56de\u503c\u9700\u8981\u5168\u9762\u68c0\u67e5&#xff0c;\u7279\u522b\u662f\u90e8\u5206\u53d1\u9001\u6216\u63a5\u6536\u7684\u60c5\u51b5\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fde\u63a5\u590d\u7528&#xff1a;\u4ee3\u7801\u4e2d\u6bcf\u6b21\u8bf7\u6c42\u90fd\u65b0\u5efa\u8fde\u63a5&#xff0c;\u6d6a\u8d39\u8d44\u6e90\u3002\u53ef\u4ee5\u590d\u7528TCP\u8fde\u63a5&#xff08;Keep-Alive&#xff09;&#xff0c;\u4f46\u5f53\u524d\u8bf7\u6c42\u4e2d\u5df2\u5305\u542bConnection: keep-alive&#xff0c;\u9700\u8981\u6b63\u786e\u5904\u7406\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>3. \u6570\u636e\u89e3\u6790<\/h4>\n<ul>\n<li>\n<p>JSON\u89e3\u6790&#xff1a;\u5e94\u4f7f\u7528cJSON\u5e93\u89e3\u6790\u54cd\u5e94\u4f53&#xff0c;\u907f\u514d\u5b57\u7b26\u4e32\u786c\u7f16\u7801\u3002\u793a\u4f8b&#xff1a;<\/p>\n<p>c<\/p>\n<p>cJSON *root &#061; cJSON_Parse(ptmpbuff);<br \/>\ncJSON *result &#061; cJSON_GetObjectItem(root, &#034;result&#034;);<br \/>\ncJSON *days &#061; cJSON_GetObjectItem(result, &#034;days&#034;);<br \/>\nprintf(&#034;days: %s\\\\n&#034;, days-&gt;valuestring);<br \/>\ncJSON_Delete(root);\n<\/li>\n<li>\n<p>\u54cd\u5e94\u683c\u5f0f\u68c0\u67e5&#xff1a;\u9700\u8981\u5148\u89e3\u6790HTTP\u72b6\u6001\u7801&#xff0c;\u786e\u4fdd\u8bf7\u6c42\u6210\u529f&#xff08;200 OK&#xff09;&#xff0c;\u518d\u5904\u7406JSON\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>4. \u4ee3\u7801\u5065\u58ee\u6027<\/h4>\n<ul>\n<li>\n<p>\u5185\u5b58\u7ba1\u7406&#xff1a;\u6240\u6709\u6307\u9488\u64cd\u4f5c\u9700\u786e\u4fdd\u4e0d\u4f1a\u8d8a\u754c&#xff0c;\u5c24\u5176\u5728\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b57\u7b26\u4e32\u62fc\u63a5&#xff1a;\u4f7f\u7528snprintf\u66ff\u4ee3sprintf\u9632\u6b62\u7f13\u51b2\u533a\u6ea2\u51fa\u3002<\/p>\n<\/li>\n<li>\n<p>\u5934\u6587\u4ef6\u4e0e\u5b8f&#xff1a;#define _GNU_SOURCE\u7528\u4e8e\u542f\u7528\u67d0\u4e9bGNU\u6269\u5c55&#xff0c;\u4f46\u4ee3\u7801\u4e2d\u672a\u4f7f\u7528\u76f8\u5173\u6269\u5c55&#xff08;\u5982memmem\u6ce8\u91ca\u6389\u4e86&#xff09;&#xff0c;\u53ef\u79fb\u9664\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>5. \u53ef\u914d\u7f6e\u6027<\/h4>\n<ul>\n<li>\n<p>\u5c06\u670d\u52a1\u5668IP\u3001\u7aef\u53e3\u3001API\u57df\u540d\u3001appkey\u7b49\u653e\u5165\u914d\u7f6e\u6587\u4ef6\u6216\u73af\u5883\u53d8\u91cf&#xff0c;\u63d0\u9ad8\u7075\u6d3b\u6027\u3002<\/p>\n<\/li>\n<li>\n<p>\u57ce\u5e02\u540dURL\u7f16\u7801&#xff1a;\u5f53\u524d\u76f4\u63a5\u62fc\u63a5&#xff0c;\u82e5\u57ce\u5e02\u5305\u542b\u4e2d\u6587\u6216\u7279\u6b8a\u5b57\u7b26&#xff0c;\u53ef\u80fd\u5bfc\u81f4\u8bf7\u6c42\u5931\u8d25\u3002\u5e94\u8fdb\u884cURL\u7f16\u7801\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>6. \u5176\u4ed6<\/h4>\n<ul>\n<li>\n<p>\u9519\u8bef\u6062\u590d&#xff1a;\u82e5\u67d0\u4e2a\u8bf7\u6c42\u5931\u8d25&#xff0c;\u5e94\u7ed9\u7528\u6237\u63d0\u793a&#xff0c;\u800c\u4e0d\u662f\u7ee7\u7eed\u89e3\u6790\u7a7a\u7f13\u51b2\u533a\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ee3\u7801\u7ed3\u6784&#xff1a;\u53ef\u4ee5\u5c06API\u8bf7\u6c42\u5c01\u88c5\u6210\u51fd\u6570&#xff0c;\u51cf\u5c11\u91cd\u590d\u4ee3\u7801\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u6539\u8fdb\u540e\u7684\u793a\u4f8b\u7247\u6bb5<\/h3>\n<p>c<\/p>\n<p>\/\/ \u5b89\u5168\u7684\u7528\u6237\u8f93\u5165<br \/>\nfgets(city, sizeof(city), stdin);<br \/>\ncity[strcspn(city, &#034;\\\\n&#034;)] &#061; &#039;\\\\0&#039;;  \/\/ \u53bb\u9664\u6362\u884c\u7b26<\/p>\n<p>\/\/ \u590d\u7528\u8fde\u63a5<br \/>\nint sockfd &#061; CreatTcpConnect(SERVER_IP, SERVER_PORT);<br \/>\nSendHttpRequest(sockfd, url_cur);<br \/>\nRecvHttpFull(sockfd, tmpbuff_cur, sizeof(tmpbuff_cur)); \/\/ \u5faa\u73af\u63a5\u6536<br \/>\n\/\/ \u89e3\u6790\u5f53\u524d\u5929\u6c14&#8230;<br \/>\nSendHttpRequest(sockfd, url_fig);  \/\/ \u590d\u7528\u540c\u4e00\u8fde\u63a5<br \/>\nRecvHttpFull(sockfd, tmpbuff_fig, sizeof(tmpbuff_fig));<br \/>\nclose(sockfd);<\/p>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u672c\u6587\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef&#xff0c;\u56de\u987e\u4e86C\u8bed\u8a00\u7f51\u7edc\u7f16\u7a0b\u7684\u57fa\u7840\u77e5\u8bc6&#xff0c;\u5305\u62ecSocket\u4f7f\u7528\u3001HTTP\u534f\u8bae\u4ea4\u4e92\u3001\u5b57\u7b26\u4e32\u5904\u7406\u7b49\u3002\u540c\u65f6\u63ed\u793a\u4e86\u4ee3\u7801\u4e2d\u5b58\u5728\u7684\u5b89\u5168\u98ce\u9669\u3001\u5065\u58ee\u6027\u95ee\u9898\u548c\u53ef\u7ef4\u62a4\u6027\u7f3a\u9677\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u5e94\u9075\u5faa\u5b89\u5168\u7f16\u7801\u89c4\u8303&#xff0c;\u4f7f\u7528\u5408\u9002\u7684\u5e93\u51fd\u6570&#xff0c;\u5e76\u5145\u5206\u8003\u8651\u7f51\u7edc\u901a\u4fe1\u7684\u590d\u6742\u6027\u548c\u6570\u636e\u7684\u53ef\u53d8\u6027\u3002\u901a\u8fc7\u91cd\u6784\u548c\u4f18\u5316&#xff0c;\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u7b80\u964b\u7684\u793a\u4f8b\u8f6c\u5316\u4e3a\u53ef\u9760\u3001\u53ef\u6269\u5c55\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u5e0c\u671b\u8fd9\u7bc7\u535a\u5ba2\u80fd\u5e2e\u52a9\u8bfb\u8005\u52a0\u6df1\u5bf9C\u7f51\u7edc\u7f16\u7a0b\u7684\u7406\u89e3&#xff0c;\u5e76\u5728\u5b9e\u8df5\u4e2d\u5199\u51fa\u66f4\u9ad8\u8d28\u91cf\u7684\u4ee3\u7801\u3002<\/p>\n<h3>\u6e90\u7801&#xff1a;<\/h3>\n<p>#define _GNU_SOURCE<br \/>\n#include &#034;cJSON.h&#034;<br \/>\n#include &#034;head.h&#034;<\/p>\n<p>int PrintfCurWeather(char *ptmp_cur)<br \/>\n{<br \/>\n    char *phead &#061; NULL;<br \/>\n    char *ptail &#061; NULL;<\/p>\n<p>    printf(&#034;&#8212;&#8212;&#8212;&#8212;&#8212;- \u4eca\u5929\u5929\u6c14 &#8212;&#8212;&#8212;&#8212;&#8211;\\\\n&#034;);<br \/>\n    phead &#061; strstr(ptmp_cur, &#034;days&#034;);<br \/>\n    phead -&#061; 1;<br \/>\n    ptail &#061; strstr(ptmp_cur, &#034;week&#034;);<br \/>\n    ptail -&#061; 2;<br \/>\n    *ptail &#061; &#039;\\\\0&#039;;<br \/>\n    printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>    ptail &#043;&#061; 1;<br \/>\n    phead &#061; strstr(ptail, &#034;week&#034;);<br \/>\n    phead -&#061; 1;<br \/>\n    ptail &#061; strstr(ptail, &#034;cityno&#034;);<br \/>\n    ptail -&#061; 2;<br \/>\n    *ptail &#061; &#039;\\\\0&#039;;<br \/>\n    printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>    ptail &#043;&#061; 1;<br \/>\n    phead &#061; strstr(ptail, &#034;citynm&#034;);<br \/>\n    phead -&#061; 1;<br \/>\n    ptail &#061; strstr(ptail, &#034;cityid&#034;);<br \/>\n    ptail -&#061; 2;<br \/>\n    *ptail &#061; &#039;\\\\0&#039;;<br \/>\n    printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>    ptail &#043;&#061; 1;<br \/>\n    phead &#061; strstr(ptail, &#034;temperature&#034;);<br \/>\n    phead -&#061; 1;<br \/>\n    ptail &#061; strstr(ptail, &#034;temperature_curr&#034;);<br \/>\n    ptail -&#061; 2;<br \/>\n    *ptail &#061; &#039;\\\\0&#039;;<br \/>\n    printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>    ptail &#043;&#061; 1;<br \/>\n    phead &#061; strstr(ptail, &#034;temperature_curr&#034;);<br \/>\n    phead -&#061; 1;<br \/>\n    ptail &#061; strstr(ptail, &#034;humidity&#034;);<br \/>\n    ptail -&#061; 2;<br \/>\n    *ptail &#061; &#039;\\\\0&#039;;<br \/>\n    printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>    ptail &#043;&#061; 1;<br \/>\n    phead &#061; strstr(ptail, &#034;humidity&#034;);<br \/>\n    phead -&#061; 1;<br \/>\n    ptail &#061; strstr(ptail, &#034;aqi&#034;);<br \/>\n    ptail -&#061; 2;<br \/>\n    *ptail &#061; &#039;\\\\0&#039;;<br \/>\n    printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>    ptail &#043;&#061; 1;<br \/>\n    phead &#061; strstr(ptail, &#034;weather&#034;);<br \/>\n    phead -&#061; 1;<br \/>\n    ptail &#061; strstr(ptail, &#034;weather_curr&#034;);<br \/>\n    ptail -&#061; 2;<br \/>\n    *ptail &#061; &#039;\\\\0&#039;;<br \/>\n    printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>    ptail &#043;&#061; 1;<br \/>\n    phead &#061; strstr(ptail, &#034;weather_curr&#034;);<br \/>\n    phead -&#061; 1;<br \/>\n    ptail &#061; strstr(ptail, &#034;weather_icon&#034;);<br \/>\n    ptail -&#061; 2;<br \/>\n    *ptail &#061; &#039;\\\\0&#039;;<br \/>\n    printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>    ptail &#043;&#061; 1;<br \/>\n    phead &#061; strstr(ptail, &#034;wind&#034;);<br \/>\n    phead -&#061; 1;<br \/>\n    ptail &#061; strstr(ptail, &#034;winp&#034;);<br \/>\n    ptail -&#061; 2;<br \/>\n    *ptail &#061; &#039;\\\\0&#039;;<br \/>\n    printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>int PrintfFigWeather(char *ptmp_fig)<br \/>\n{<br \/>\n    char *phead &#061; NULL;<br \/>\n    char *ptail &#061; NULL;<\/p>\n<p>    ptail &#061; ptmp_fig;<\/p>\n<p>    printf(&#034;&#8212;&#8212;&#8212;&#8212;&#8212;- \u672a\u6765\u51e0\u5929\u5929\u6c14 &#8212;&#8212;&#8212;&#8212;&#8211;\\\\n&#034;);<\/p>\n<p>    while(1)<br \/>\n    {<br \/>\n        phead &#061; strstr(ptail, &#034;days&#034;);<br \/>\n        if(NULL &#061;&#061; phead)<br \/>\n        {<br \/>\n            break;<br \/>\n        }<br \/>\n        phead -&#061; 1;<br \/>\n        ptail &#061; strstr(ptail, &#034;week&#034;);<br \/>\n        ptail -&#061; 2;<br \/>\n        *ptail &#061; &#039;\\\\0&#039;;<br \/>\n        printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>        ptail &#043;&#061; 1;<br \/>\n        phead &#061; strstr(ptail, &#034;week&#034;);<br \/>\n        phead -&#061; 1;<br \/>\n        ptail &#061; strstr(ptail, &#034;cityno&#034;);<br \/>\n        ptail -&#061; 2;<br \/>\n        *ptail &#061; &#039;\\\\0&#039;;<br \/>\n        printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>        ptail &#043;&#061; 1;<br \/>\n        phead &#061; strstr(ptail, &#034;citynm&#034;);<br \/>\n        phead -&#061; 1;<br \/>\n        ptail &#061; strstr(ptail, &#034;cityid&#034;);<br \/>\n        ptail -&#061; 2;<br \/>\n        *ptail &#061; &#039;\\\\0&#039;;<br \/>\n        printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>        ptail &#043;&#061; 1;<br \/>\n        phead &#061; strstr(ptail, &#034;temperature&#034;);<br \/>\n        phead -&#061; 1;<br \/>\n        ptail &#061; strstr(ptail, &#034;humidity&#034;);<br \/>\n        ptail -&#061; 2;<br \/>\n        *ptail &#061; &#039;\\\\0&#039;;<br \/>\n        printf(&#034;%s\\\\n&#034;, phead);<\/p>\n<p>        ptail &#043;&#061; 1;<br \/>\n        phead &#061; strstr(ptail, &#034;weather&#034;);<br \/>\n        phead -&#061; 1;<br \/>\n        ptail &#061; strstr(ptail, &#034;weather_icon&#034;);<br \/>\n        ptail -&#061; 2;<br \/>\n        *ptail &#061; &#039;\\\\0&#039;;<br \/>\n        printf(&#034;%s\\\\n&#034;, phead);<br \/>\n        ptail &#043;&#061; 1;<\/p>\n<p>        printf(&#034;\\\\n\\\\n&#034;);<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>int CreatTcpConnect(char *pserip, int port)<br \/>\n{<br \/>\n    int ret &#061; 0;<br \/>\n    int sockfd &#061; 0;<br \/>\n    struct sockaddr_in serveaddr;<\/p>\n<p>    sockfd &#061; socket(AF_INET, SOCK_STREAM, 0);<br \/>\n    if(-1 &#061;&#061; sockfd)<br \/>\n    {<br \/>\n        perror(&#034;fail to socket&#034;);<br \/>\n        return -1;<br \/>\n    }<\/p>\n<p>    serveaddr.sin_family &#061; AF_INET;<br \/>\n    serveaddr.sin_port &#061; htons(port);<br \/>\n    serveaddr.sin_addr.s_addr &#061; inet_addr(pserip);<br \/>\n    ret &#061; connect(sockfd, (struct sockaddr *)&amp;serveaddr, sizeof(serveaddr));<br \/>\n    if(-1 &#061;&#061; ret)<br \/>\n    {<br \/>\n        perror(&#034;fail to connect&#034;);<br \/>\n        return -1;<br \/>\n    }<\/p>\n<p>    return sockfd;<br \/>\n}<\/p>\n<p>int SendHttpRequest(int sockfd, char *purl)<br \/>\n{<br \/>\n    ssize_t nret &#061; 0;<br \/>\n    char tmpbuff[4096] &#061; {0};<\/p>\n<p>    sprintf(tmpbuff, &#034;GET %s HTTP\/1.1\\\\r\\\\n&#034;, purl);<br \/>\n    sprintf(tmpbuff, &#034;%sHost: api.k780.com\\\\r\\\\n&#034;, tmpbuff);<br \/>\n    sprintf(tmpbuff, &#034;%sUser-Agent: Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko\/20100101 Firefox\/113.0\\\\r\\\\n&#034;, tmpbuff);<br \/>\n    sprintf(tmpbuff, &#034;%sAccept: text\/html,application\/xhtml&#043;xml,application\/xml;q&#061;0.9,image\/avif,image\/webp,*\/*;q&#061;0.8\\\\r\\\\n&#034;, tmpbuff);<br \/>\n    sprintf(tmpbuff, &#034;%sAccept-Language: en-US,en;q&#061;0.5\\\\r\\\\n&#034;, tmpbuff);<br \/>\n    sprintf(tmpbuff, &#034;%sAccept-Encoding: gzip, deflate\\\\r\\\\n&#034;, tmpbuff);<br \/>\n    sprintf(tmpbuff, &#034;%sConnection: keep-alive\\\\r\\\\n&#034;, tmpbuff);<br \/>\n    sprintf(tmpbuff, &#034;%sUpgrade-Insecure-Requests: 1\\\\r\\\\n&#034;, tmpbuff);<br \/>\n    sprintf(tmpbuff, &#034;%s\\\\r\\\\n&#034;, tmpbuff);<\/p>\n<p>    nret &#061; send(sockfd, tmpbuff, strlen(tmpbuff), 0);<br \/>\n    if(-1 &#061;&#061; nret)<br \/>\n    {<br \/>\n        perror(&#034;fail to send&#034;);<br \/>\n        return -1;<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>int RecvHttpRespone(int sockfd, char *ptmpbuff, int maxlen)<br \/>\n{<br \/>\n    ssize_t nret &#061; 0;<\/p>\n<p>    nret &#061; recv(sockfd, ptmpbuff, maxlen, 0);<br \/>\n    if(-1 &#061;&#061; nret)<br \/>\n    {<br \/>\n        perror(&#034;fail to recv&#034;);<br \/>\n        return -1;<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n    int sockfd &#061; 0;<br \/>\n    char city[32] &#061; {0};<br \/>\n    char url_cur[1024] &#061; {0};<br \/>\n    char url_fig[1024] &#061; {0};<br \/>\n    char tmpbuff_cur[4096] &#061; {0};<br \/>\n    char tmpbuff_fig[8192] &#061; {0};<br \/>\n    char *ptmp &#061; NULL;<\/p>\n<p>    printf(&#034;\u8bf7\u8f93\u5165\u8981\u67e5\u8be2\u7684\u57ce\u5e02&#xff1a;\\\\n&#034;);<br \/>\n    gets(city);<\/p>\n<p>    sprintf(url_cur, &#034;\/?app&#061;weather.today&amp;weaid&#061;%s&amp;appkey&#061;78642&amp;sign&#061;9d7c0f5b3bf9aa6b1b9a29d23ae66215&amp;format&#061;json&#034;,city);<\/p>\n<p>    sockfd &#061; CreatTcpConnect(&#034;103.205.5.206&#034;, 80);<\/p>\n<p>    SendHttpRequest(sockfd, url_cur);<\/p>\n<p>    RecvHttpRespone(sockfd, tmpbuff_cur, sizeof(tmpbuff_cur));<\/p>\n<p>    close(sockfd);<\/p>\n<p>    sprintf(url_fig, &#034;http:\/\/api.k780.com\/?app&#061;weather.future&amp;weaid&#061;%s&amp;appkey&#061;78642&amp;sign&#061;9d7c0f5b3bf9aa6b1b9a29d23ae66215&amp;format&#061;json&#034;,city);<\/p>\n<p>    sockfd &#061; CreatTcpConnect(&#034;103.205.5.206&#034;, 80);<\/p>\n<p>    SendHttpRequest(sockfd, url_fig);<\/p>\n<p>    RecvHttpRespone(sockfd, tmpbuff_fig, sizeof(tmpbuff_fig));<\/p>\n<p>    close(sockfd);<\/p>\n<p>    PrintfCurWeather(tmpbuff_cur);<\/p>\n<p>    PrintfFigWeather(tmpbuff_fig);<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<h3>\u7ed3\u679c\u5c55\u793a&#xff1a;<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1095\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305144415-69a996bf2632f.png\" width=\"1381\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u8a00\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u6216\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u4e2d&#xff0c;\u901a\u8fc7Socket\u7f16\u7a0b\u4e0eWeb API\u4ea4\u4e92\u662f\u4e00\u9879\u57fa\u7840\u800c\u91cd\u8981\u7684\u6280\u80fd\u3002\u672c\u6587\u57fa\u4e8e\u4e00\u6bb5\u5b9e\u9645\u7f16\u5199\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u4ee3\u7801&#xff0c;\u8be6\u7ec6\u5206\u6790\u5176\u5b9e\u73b0\u539f\u7406\u3001\u6280\u672f\u8981\u70b9&#xff0c;\u5e76\u63a2\u8ba8\u5176\u4e2d\u5b58\u5728\u7684\u95ee\u9898\u4e0e\u4f18\u5316\u65b9\u5411\u3002\u8be5\u5ba2\u6237\u7aef\u901a\u8fc7TCP\u8fde\u63a5\u5411\u8fdc\u7a0b\u670d\u52a1\u5668\u53d1\u9001HTTP\u8bf7\u6c42&#xff0c;\u83b7\u53d6JSON\u683c\u5f0f\u7684\u5929\u6c14\u6570\u636e&#xff0c;\u5e76\u901a\u8fc7\u5b57\u7b26\u4e32\u64cd\u4f5c\u63d0\u53d6\u5173\u952e\u4fe1\u606f\u6253\u5370\u663e\u793a\u3002\u6d89\u53ca\u7684\u6280\u672f\u70b9Socket\u7f51\u7edc\u7f16\u7a0b&#xff1a;\u521b\u5efaTCP\u5957\u63a5\u5b57&#xff0c;\u8fde\u63a5\u5230\u6307\u5b9a<\/p>\n","protected":false},"author":2,"featured_media":80757,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[174,151,190],"topic":[],"class_list":["post-80758","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-http","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u57fa\u4e8eC\u8bed\u8a00\u548cHTTP API\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e0e\u5206\u6790 - \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\/80758.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u57fa\u4e8eC\u8bed\u8a00\u548cHTTP API\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e0e\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5f15\u8a00\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u6216\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u4e2d&#xff0c;\u901a\u8fc7Socket\u7f16\u7a0b\u4e0eWeb API\u4ea4\u4e92\u662f\u4e00\u9879\u57fa\u7840\u800c\u91cd\u8981\u7684\u6280\u80fd\u3002\u672c\u6587\u57fa\u4e8e\u4e00\u6bb5\u5b9e\u9645\u7f16\u5199\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u4ee3\u7801&#xff0c;\u8be6\u7ec6\u5206\u6790\u5176\u5b9e\u73b0\u539f\u7406\u3001\u6280\u672f\u8981\u70b9&#xff0c;\u5e76\u63a2\u8ba8\u5176\u4e2d\u5b58\u5728\u7684\u95ee\u9898\u4e0e\u4f18\u5316\u65b9\u5411\u3002\u8be5\u5ba2\u6237\u7aef\u901a\u8fc7TCP\u8fde\u63a5\u5411\u8fdc\u7a0b\u670d\u52a1\u5668\u53d1\u9001HTTP\u8bf7\u6c42&#xff0c;\u83b7\u53d6JSON\u683c\u5f0f\u7684\u5929\u6c14\u6570\u636e&#xff0c;\u5e76\u901a\u8fc7\u5b57\u7b26\u4e32\u64cd\u4f5c\u63d0\u53d6\u5173\u952e\u4fe1\u606f\u6253\u5370\u663e\u793a\u3002\u6d89\u53ca\u7684\u6280\u672f\u70b9Socket\u7f51\u7edc\u7f16\u7a0b&#xff1a;\u521b\u5efaTCP\u5957\u63a5\u5b57&#xff0c;\u8fde\u63a5\u5230\u6307\u5b9a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/80758.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-03-05T14:44:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305144415-69a996bf2632f.png\" \/>\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\/80758.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/80758.html\",\"name\":\"\u57fa\u4e8eC\u8bed\u8a00\u548cHTTP API\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e0e\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-03-05T14:44:16+00:00\",\"dateModified\":\"2026-03-05T14:44:16+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/80758.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/80758.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/80758.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u57fa\u4e8eC\u8bed\u8a00\u548cHTTP API\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e0e\u5206\u6790\"}]},{\"@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":"\u57fa\u4e8eC\u8bed\u8a00\u548cHTTP API\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e0e\u5206\u6790 - \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\/80758.html","og_locale":"zh_CN","og_type":"article","og_title":"\u57fa\u4e8eC\u8bed\u8a00\u548cHTTP API\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e0e\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5f15\u8a00\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u6216\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u4e2d&#xff0c;\u901a\u8fc7Socket\u7f16\u7a0b\u4e0eWeb API\u4ea4\u4e92\u662f\u4e00\u9879\u57fa\u7840\u800c\u91cd\u8981\u7684\u6280\u80fd\u3002\u672c\u6587\u57fa\u4e8e\u4e00\u6bb5\u5b9e\u9645\u7f16\u5199\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u4ee3\u7801&#xff0c;\u8be6\u7ec6\u5206\u6790\u5176\u5b9e\u73b0\u539f\u7406\u3001\u6280\u672f\u8981\u70b9&#xff0c;\u5e76\u63a2\u8ba8\u5176\u4e2d\u5b58\u5728\u7684\u95ee\u9898\u4e0e\u4f18\u5316\u65b9\u5411\u3002\u8be5\u5ba2\u6237\u7aef\u901a\u8fc7TCP\u8fde\u63a5\u5411\u8fdc\u7a0b\u670d\u52a1\u5668\u53d1\u9001HTTP\u8bf7\u6c42&#xff0c;\u83b7\u53d6JSON\u683c\u5f0f\u7684\u5929\u6c14\u6570\u636e&#xff0c;\u5e76\u901a\u8fc7\u5b57\u7b26\u4e32\u64cd\u4f5c\u63d0\u53d6\u5173\u952e\u4fe1\u606f\u6253\u5370\u663e\u793a\u3002\u6d89\u53ca\u7684\u6280\u672f\u70b9Socket\u7f51\u7edc\u7f16\u7a0b&#xff1a;\u521b\u5efaTCP\u5957\u63a5\u5b57&#xff0c;\u8fde\u63a5\u5230\u6307\u5b9a","og_url":"https:\/\/www.wsisp.com\/helps\/80758.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-03-05T14:44:16+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305144415-69a996bf2632f.png"}],"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\/80758.html","url":"https:\/\/www.wsisp.com\/helps\/80758.html","name":"\u57fa\u4e8eC\u8bed\u8a00\u548cHTTP API\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e0e\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-03-05T14:44:16+00:00","dateModified":"2026-03-05T14:44:16+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/80758.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/80758.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/80758.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u57fa\u4e8eC\u8bed\u8a00\u548cHTTP API\u7684\u5929\u6c14\u67e5\u8be2\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e0e\u5206\u6790"}]},{"@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\/80758","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=80758"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/80758\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/80757"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=80758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=80758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=80758"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=80758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}