2024-09-19 08:29:13 +00:00

70 lines
25 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>ZMRequest HTTP 客户端 | 炸毛框架 v3</title>
<meta name="description" content="">
<meta name="generator" content="VuePress 1.9.10">
<link rel="icon" href="/logo_trans.png">
<script>
var _hmt = _hmt || [];
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?f0f276cefa10aa31a20ae3815a50b795";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<meta name="description" content="一个高性能聊天机器人 + Web 框架">
<link rel="preload" href="/assets/css/0.styles.de075592.css" as="style"><link rel="preload" href="/assets/js/app.cf958133.js" as="script"><link rel="preload" href="/assets/js/2.4c04991c.js" as="script"><link rel="preload" href="/assets/js/1.d8755a39.js" as="script"><link rel="preload" href="/assets/js/40.57eba153.js" as="script"><link rel="prefetch" href="/assets/js/10.960912c3.js"><link rel="prefetch" href="/assets/js/11.cd171694.js"><link rel="prefetch" href="/assets/js/12.ff9ca1d1.js"><link rel="prefetch" href="/assets/js/13.a56deac8.js"><link rel="prefetch" href="/assets/js/14.b222a011.js"><link rel="prefetch" href="/assets/js/15.31489867.js"><link rel="prefetch" href="/assets/js/16.e921dbc4.js"><link rel="prefetch" href="/assets/js/17.58f730d3.js"><link rel="prefetch" href="/assets/js/18.26c46c49.js"><link rel="prefetch" href="/assets/js/19.ee0bfd3b.js"><link rel="prefetch" href="/assets/js/20.bb3578b8.js"><link rel="prefetch" href="/assets/js/21.e66f7fe5.js"><link rel="prefetch" href="/assets/js/22.cba8ca48.js"><link rel="prefetch" href="/assets/js/23.cb49f41c.js"><link rel="prefetch" href="/assets/js/24.d95b175a.js"><link rel="prefetch" href="/assets/js/25.b0d69869.js"><link rel="prefetch" href="/assets/js/26.8e7089c0.js"><link rel="prefetch" href="/assets/js/27.333a53a1.js"><link rel="prefetch" href="/assets/js/28.df4b871c.js"><link rel="prefetch" href="/assets/js/29.5427ad45.js"><link rel="prefetch" href="/assets/js/3.07fc018e.js"><link rel="prefetch" href="/assets/js/30.7cb7445a.js"><link rel="prefetch" href="/assets/js/31.5c4bb546.js"><link rel="prefetch" href="/assets/js/32.7fc05474.js"><link rel="prefetch" href="/assets/js/33.9684a4f8.js"><link rel="prefetch" href="/assets/js/34.83e32a28.js"><link rel="prefetch" href="/assets/js/35.95d03df6.js"><link rel="prefetch" href="/assets/js/36.80aace42.js"><link rel="prefetch" href="/assets/js/37.1eaed2ee.js"><link rel="prefetch" href="/assets/js/38.75fa7a1c.js"><link rel="prefetch" href="/assets/js/39.117f5802.js"><link rel="prefetch" href="/assets/js/4.6623271b.js"><link rel="prefetch" href="/assets/js/41.89c4a7c8.js"><link rel="prefetch" href="/assets/js/42.d8f92f99.js"><link rel="prefetch" href="/assets/js/43.5ee83631.js"><link rel="prefetch" href="/assets/js/44.c09b5b0c.js"><link rel="prefetch" href="/assets/js/45.bd850606.js"><link rel="prefetch" href="/assets/js/46.732b1cef.js"><link rel="prefetch" href="/assets/js/47.2a872d0d.js"><link rel="prefetch" href="/assets/js/48.959e18f4.js"><link rel="prefetch" href="/assets/js/49.a9bb32f7.js"><link rel="prefetch" href="/assets/js/5.073233e8.js"><link rel="prefetch" href="/assets/js/50.ca90a854.js"><link rel="prefetch" href="/assets/js/51.79142530.js"><link rel="prefetch" href="/assets/js/52.fe63ad16.js"><link rel="prefetch" href="/assets/js/53.ed84845a.js"><link rel="prefetch" href="/assets/js/54.3ab7e492.js"><link rel="prefetch" href="/assets/js/55.9028e407.js"><link rel="prefetch" href="/assets/js/56.8173f798.js"><link rel="prefetch" href="/assets/js/57.2166b068.js"><link rel="prefetch" href="/assets/js/58.7c52b6bf.js"><link rel="prefetch" href="/assets/js/59.e9965a7b.js"><link rel="prefetch" href="/assets/js/60.f277436c.js"><link rel="prefetch" href="/assets/js/61.3712f8fe.js"><link rel="prefetch" href="/assets/js/8.899a0731.js"><link rel="prefetch" href="/assets/js/9.e2e8da12.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.303532f0.js">
<link rel="stylesheet" href="/assets/css/0.styles.de075592.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="ant-row"><div class="nav-button"><i aria-label="icon: bars" class="anticon anticon-bars"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="bars" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M912 192H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM104 228a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path></svg></i> <span></span></div> <div class="ant-col ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-6 ant-col-xl-5 ant-col-xxl-4"><a href="/" class="router-link-active home-link"><img src="/logo_trans.png" alt="炸毛框架 v3" class="logo"> <span class="site-name">炸毛框架 v3</span></a> <div class="search-box mobile-search"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div></div> <div class="nav-space-between ant-col ant-col-xs-0 ant-col-sm-0 ant-col-md-18 ant-col-lg-18 ant-col-xl-19 ant-col-xxl-20"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><ul role="menu" id="nav" class="ant-menu ant-menu-horizontal ant-menu-root ant-menu-light"><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/guide/">
指南
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/event/">
事件
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/components/bot/bot-context.html">
组件
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/plugins/management.html">
插件
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/advanced/">
进阶
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/update/v3.html">
更新日志
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/doxy/" target="_blank">
API 文档
<i aria-label="icon: link" class="anticon anticon-link"><svg viewBox="64 64 896 896" focusable="false" data-icon="link" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M574 665.4a8.03 8.03 0 0 0-11.3 0L446.5 781.6c-53.8 53.8-144.6 59.5-204 0-59.5-59.5-53.8-150.2 0-204l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3l-39.8-39.8a8.03 8.03 0 0 0-11.3 0L191.4 526.5c-84.6 84.6-84.6 221.5 0 306s221.5 84.6 306 0l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3L574 665.4zm258.6-474c-84.6-84.6-221.5-84.6-306 0L410.3 307.6a8.03 8.03 0 0 0 0 11.3l39.7 39.7c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c53.8-53.8 144.6-59.5 204 0 59.5 59.5 53.8 150.2 0 204L665.3 562.6a8.03 8.03 0 0 0 0 11.3l39.8 39.8c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c84.5-84.6 84.5-221.5 0-306.1zM610.1 372.3a8.03 8.03 0 0 0-11.3 0L372.3 598.7a8.03 8.03 0 0 0 0 11.3l39.6 39.6c3.1 3.1 8.2 3.1 11.3 0l226.4-226.4c3.1-3.1 3.1-8.2 0-11.3l-39.5-39.6z"></path></svg></i></a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="https://docs-v2.zhamao.xin/" target="_blank">
炸毛框架 v2
<i aria-label="icon: link" class="anticon anticon-link"><svg viewBox="64 64 896 896" focusable="false" data-icon="link" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M574 665.4a8.03 8.03 0 0 0-11.3 0L446.5 781.6c-53.8 53.8-144.6 59.5-204 0-59.5-59.5-53.8-150.2 0-204l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3l-39.8-39.8a8.03 8.03 0 0 0-11.3 0L191.4 526.5c-84.6 84.6-84.6 221.5 0 306s221.5 84.6 306 0l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3L574 665.4zm258.6-474c-84.6-84.6-221.5-84.6-306 0L410.3 307.6a8.03 8.03 0 0 0 0 11.3l39.7 39.7c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c53.8-53.8 144.6-59.5 204 0 59.5 59.5 53.8 150.2 0 204L665.3 562.6a8.03 8.03 0 0 0 0 11.3l39.8 39.8c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c84.5-84.6 84.5-221.5 0-306.1zM610.1 372.3a8.03 8.03 0 0 0-11.3 0L372.3 598.7a8.03 8.03 0 0 0 0 11.3l39.6 39.6c3.1 3.1 8.2 3.1 11.3 0l226.4-226.4c3.1-3.1 3.1-8.2 0-11.3l-39.5-39.6z"></path></svg></i></a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="visibility:hidden;position:absolute;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li></ul> <ul class="extra-group"><li><a href="https://github.com/zhamao-robot/zhamao-framework" target="_blank" rel="noopener noreferrer" class="repo-link"><i aria-label="icon: github" class="anticon anticon-github"><svg viewBox="64 64 896 896" focusable="false" data-icon="github" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M511.6 76.3C264.3 76.2 64 276.4 64 523.5 64 718.9 189.3 885 363.8 946c23.5 5.9 19.9-10.8 19.9-22.2v-77.5c-135.7 15.9-141.2-73.9-150.3-88.9C215 726 171.5 718 184.5 703c30.9-15.9 62.4 4 98.9 57.9 26.4 39.1 77.9 32.5 104 26 5.7-23.5 17.9-44.5 34.7-60.8-140.6-25.2-199.2-111-199.2-213 0-49.5 16.3-95 48.3-131.7-20.4-60.5 1.9-112.3 4.9-120 58.1-5.2 118.5 41.6 123.2 45.3 33-8.9 70.7-13.6 112.9-13.6 42.4 0 80.2 4.9 113.5 13.9 11.3-8.6 67.3-48.8 121.3-43.9 2.9 7.7 24.7 58.3 5.5 118 32.4 36.8 48.9 82.7 48.9 132.3 0 102.2-59 188.1-200 212.9a127.5 127.5 0 0 1 38.1 91v112.5c.8 9 0 17.9 15 17.9 177.1-59.7 304.6-227 304.6-424.1 0-247.2-200.4-447.3-447.5-447.3z"></path></svg></i></a></li> <!----></ul></nav></div></div> <!----></header> <aside class="sidebar"><!----> <ul class="sidebar-links"><li><a href="/components/" aria-current="page" title="组件" class="sidebar-link">组件</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>机器人组件</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>HTTP 组件</span> <span class="arrow down"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/components/http/zmrequest.html" aria-current="page" title="ZMRequest HTTP 客户端" class="active sidebar-link">ZMRequest HTTP 客户端</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/components/http/zmrequest.html#使用" title="使用" class="sidebar-link">使用</a></li><li class="sidebar-sub-header"><a href="/components/http/zmrequest.html#响应" title="响应" class="sidebar-link">响应</a></li><li class="sidebar-sub-header"><a href="/components/http/zmrequest.html#错误处理" title="错误处理" class="sidebar-link">错误处理</a></li></ul></li><li><a href="/components/http/websocket-access.html" title="接入其他 WebSocket 客户端" class="sidebar-link">接入其他 WebSocket 客户端</a></li><li><a href="/components/http/websocket-client.html" title="框架内置 WebSocket 客户端" class="sidebar-link">框架内置 WebSocket 客户端</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>框架通用组件</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>存储组件</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>依赖注入组件</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li></ul> </aside> <main class="page has-page-anchor"> <div class="theme-antdocs-content content__default"><h1 id="zmrequest-http-客户端"><a href="#zmrequest-http-客户端" class="header-anchor">#</a> ZMRequest HTTP 客户端</h1> <p>ZMRequest 是基于底层 PSR-18 封装的 HTTP 客户端,支持 HTTP/HTTPS 协议,方便用户快速实现 HTTP 请求。</p> <h2 id="使用"><a href="#使用" class="header-anchor">#</a> 使用</h2> <p>目前ZMRequest 提供 GET 和 POST 两种请求方式,使用方式如下:</p> <div class="language-php line-numbers-mode"><pre class="language-php"><code><span class="token keyword">use</span> <span class="token package">ZM<span class="token punctuation">\</span>Utils<span class="token punctuation">\</span>ZMRequest</span><span class="token punctuation">;</span>
<span class="token comment">// GET 请求</span>
<span class="token variable">$response</span> <span class="token operator">=</span> <span class="token class-name static-context">ZMRequest</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'https://httpbin.org/get'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// POST 请求</span>
<span class="token variable">$response</span> <span class="token operator">=</span> <span class="token class-name static-context">ZMRequest</span><span class="token operator">::</span><span class="token function">post</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'https://httpbin.org/post'</span><span class="token punctuation">,</span> <span class="token argument-name">data</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string single-quoted-string">'foo'</span> <span class="token operator">=&gt;</span> <span class="token string single-quoted-string">'bar'</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h2 id="响应"><a href="#响应" class="header-anchor">#</a> 响应</h2> <p>ZMRequest 的响应取决于 <code>only_body</code> 参数,如果为 <code>true</code>,则只返回响应体(<code>string</code>),否则返回完整的响应(<code>ResponseInterface</code>)。</p> <p>默认情况下,<code>only_body</code><code>true</code>,即只返回响应体。</p> <div class="language-php line-numbers-mode"><pre class="language-php"><code><span class="token keyword">use</span> <span class="token package">ZM<span class="token punctuation">\</span>Utils<span class="token punctuation">\</span>ZMRequest</span><span class="token punctuation">;</span>
<span class="token comment">// 只返回响应体</span>
<span class="token variable">$response</span> <span class="token operator">=</span> <span class="token class-name static-context">ZMRequest</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'https://httpbin.org/get'</span><span class="token punctuation">,</span> <span class="token argument-name">only_body</span><span class="token punctuation">:</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 返回完整的响应</span>
<span class="token variable">$response</span> <span class="token operator">=</span> <span class="token class-name static-context">ZMRequest</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'https://httpbin.org/get'</span><span class="token punctuation">,</span> <span class="token argument-name">only_body</span><span class="token punctuation">:</span> <span class="token constant boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$content</span> <span class="token operator">=</span> <span class="token variable">$response</span><span class="token operator">-&gt;</span><span class="token function">getBody</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">getContents</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="错误处理"><a href="#错误处理" class="header-anchor">#</a> 错误处理</h2> <p>在请求失败或异常时ZMRequest 的 <code>get</code><code>post</code> 方法会返回 <code>false</code>,用户需要自行处理错误。</p> <div class="language-php line-numbers-mode"><pre class="language-php"><code><span class="token keyword">use</span> <span class="token package">ZM<span class="token punctuation">\</span>Utils<span class="token punctuation">\</span>ZMRequest</span><span class="token punctuation">;</span>
<span class="token variable">$response</span> <span class="token operator">=</span> <span class="token class-name static-context">ZMRequest</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'https://httpbin.org/get'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$response</span> <span class="token operator">===</span> <span class="token constant boolean">false</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token comment">// 请求失败或异常</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/zhamao-robot/zhamao-framework/edit/main/docs/components/http/zmrequest.md" target="_blank" rel="noopener noreferrer">Edit this page</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/components/bot/authorization.html" class="prev"><i aria-label="icon: left" class="anticon anticon-left"><svg viewBox="64 64 896 896" focusable="false" data-icon="left" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 0 0 0 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"></path></svg></i>
机器人接入鉴权
</a></span> <span class="next"><a href="/components/http/websocket-access.html">
接入其他 WebSocket 客户端
<i aria-label="icon: right" class="anticon anticon-right"><svg viewBox="64 64 896 896" focusable="false" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path></svg></i></a></span></p></div> <div class="page-anchor"><div class="ant-space ant-space-vertical" style="width:100%;"><div class="ant-space-item"><div class="page-anchor-offset"><div><div class="ant-anchor-wrapper" style="max-height:100vh;"><div class="ant-anchor"><div class="ant-anchor-ink"><span class="ant-anchor-ink-ball"></span></div><div class="ant-anchor-link"><a href="#使用" title="使用" class="ant-anchor-link-title">使用</a></div><div class="ant-anchor-link"><a href="#响应" title="响应" class="ant-anchor-link-title">响应</a></div><div class="ant-anchor-link"><a href="#错误处理" title="错误处理" class="ant-anchor-link-title">错误处理</a></div></div></div></div></div></div></div></div> </main> <!----></div><div class="global-ui"></div></div>
<script src="/assets/js/app.cf958133.js" defer></script><script src="/assets/js/2.4c04991c.js" defer></script><script src="/assets/js/1.d8755a39.js" defer></script><script src="/assets/js/40.57eba153.js" defer></script>
</body>
</html>