🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# axios网络请求 # 特点 - 在浏览器中发送XMLHttpRequests请求 - 在node.js中发送http请求 - 支持Promise API - 拦截请求和响应 - 转换请求和响应数据 - 等等 **安装** ``` <pre class="calibre13">``` npm install axios <span class="token">--</span>save ``` ``` # 实例 默认get请求 ``` <pre class="calibre13">``` <span class="token">~</span><span class="token">~</span><span class="token">~</span> <span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'http://httpbin.org/get'</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> <span class="token">~</span><span class="token">~</span><span class="token">~</span> ``` ``` post请求: ``` <pre class="calibre13">``` <span class="token">~</span><span class="token">~</span><span class="token">~</span> <span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'http://httpbin.org/post'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'post'</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> <span class="token">~</span><span class="token">~</span><span class="token">~</span> ``` ``` # 提交参数方式: get 和params对应 post和data对应 ``` <pre class="calibre13">``` <span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'http://httpbin.org/get?id=2'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'get'</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> ``` ``` ``` <pre class="calibre13">``` <span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'http://httpbin.org/get'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'get'</span><span class="token1">,</span> params<span class="token1">:</span> <span class="token1">{</span> uid<span class="token1">:</span> <span class="token4">'11'</span><span class="token1">,</span> age<span class="token1">:</span> <span class="token5">18</span> <span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> ``` ``` ``` <pre class="calibre13">``` <span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'http://httpbin.org/post'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'post'</span><span class="token1">,</span> data<span class="token1">:</span><span class="token1">{</span>uid<span class="token1">:</span><span class="token5">12</span><span class="token1">,</span>age<span class="token1">:</span><span class="token5">18</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token2">catch</span><span class="token1">(</span>err <span class="token">=></span><span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>err<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> ``` ``` ``` <pre class="calibre13">``` <span class="token6">// 并发请求</span> axios<span class="token1">.</span><span class="token3">all</span><span class="token1">(</span><span class="token1">[</span><span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'http://httpbin.org/get'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'get'</span><span class="token1">,</span> params<span class="token1">:</span><span class="token1">{</span>username<span class="token1">:</span> <span class="token4">'张三'</span><span class="token1">,</span> age<span class="token1">:</span> <span class="token5">18</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">,</span><span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'http://httpbin.org/post'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'post'</span><span class="token1">,</span> data<span class="token1">:</span> <span class="token1">{</span>username<span class="token1">:</span> <span class="token4">'李四'</span><span class="token1">,</span>age<span class="token1">:</span> <span class="token5">20</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">]</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>results <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>results<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> ``` ``` ``` <pre class="calibre13">``` <span class="token6">// 并发请求 axios.all([])返回的结果是一个数组,使用axios.spread可将数组【res1,res2】展开为res1,res2</span> axios<span class="token1">.</span><span class="token3">all</span><span class="token1">(</span><span class="token1">[</span><span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'http://httpbin.org/get'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'get'</span><span class="token1">,</span> params<span class="token1">:</span><span class="token1">{</span>username<span class="token1">:</span> <span class="token4">'张三'</span><span class="token1">,</span> age<span class="token1">:</span> <span class="token5">18</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">,</span><span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'http://httpbin.org/post'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'post'</span><span class="token1">,</span> data<span class="token1">:</span> <span class="token1">{</span>username<span class="token1">:</span> <span class="token4">'李四'</span><span class="token1">,</span>age<span class="token1">:</span> <span class="token5">20</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">]</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>axios<span class="token1">.</span><span class="token3">spread</span><span class="token1">(</span><span class="token1">(</span>res1<span class="token1">,</span>res2<span class="token1">)</span> <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res1<span class="token1">)</span><span class="token1">;</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res2<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> <span class="token1">)</span> ``` ``` # axios全局配置 ``` <pre class="calibre13">``` <span class="token6">// 并发请求 并全局配置</span> axios<span class="token1">.</span>defaults<span class="token1">.</span>baseURL <span class="token">=</span> <span class="token4">'http://httpbin.org'</span><span class="token1">;</span> axios<span class="token1">.</span>defaults<span class="token1">.</span>timeout <span class="token">=</span> <span class="token5">5000</span><span class="token1">;</span> <span class="token6">//单位毫秒</span> axios<span class="token1">.</span><span class="token3">all</span><span class="token1">(</span><span class="token1">[</span><span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'/get'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'get'</span><span class="token1">,</span> params<span class="token1">:</span><span class="token1">{</span>username<span class="token1">:</span> <span class="token4">'张三'</span><span class="token1">,</span> age<span class="token1">:</span> <span class="token5">18</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">,</span><span class="token3">axios</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'/post'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'post'</span><span class="token1">,</span> data<span class="token1">:</span> <span class="token1">{</span>username<span class="token1">:</span> <span class="token4">'李四'</span><span class="token1">,</span>age<span class="token1">:</span> <span class="token5">20</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">]</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>axios<span class="token1">.</span><span class="token3">spread</span><span class="token1">(</span><span class="token1">(</span>res1<span class="token1">,</span>res2<span class="token1">)</span> <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res1<span class="token1">)</span><span class="token1">;</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res2<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> <span class="token1">)</span> ``` ``` 上面是使用全局的axios和对应的配置进行网络请求 如果分布式服务器 发送不同的服务器 就不能那么用了 需要使用实例: ``` <pre class="calibre13">``` <span class="token6">//创建axios实例:</span> <span class="token2">const</span> instance1 <span class="token">=</span> axios<span class="token1">.</span><span class="token3">create</span><span class="token1">(</span><span class="token1">{</span> baseURL<span class="token1">:</span> <span class="token4">'http://httpbin.org'</span><span class="token1">,</span> timeout<span class="token1">:</span> <span class="token5">5000</span> <span class="token1">}</span><span class="token1">)</span> <span class="token2">const</span> instance2 <span class="token">=</span> axios<span class="token1">.</span><span class="token3">create</span><span class="token1">(</span><span class="token1">{</span> baseURL<span class="token1">:</span> <span class="token4">'http://expressjs.jser.us'</span><span class="token1">,</span> timeout<span class="token1">:</span> <span class="token5">5000</span> <span class="token1">}</span><span class="token1">)</span> <span class="token6">// 使用实例</span> <span class="token3">instance1</span><span class="token1">(</span><span class="token1">{</span> url <span class="token1">:</span><span class="token4">'/get'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'get'</span><span class="token1">,</span> params<span class="token1">:</span> <span class="token1">{</span>username<span class="token1">:</span> <span class="token4">'张三'</span><span class="token1">,</span>age<span class="token1">:</span> <span class="token5">18</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> <span class="token3">instance1</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'/post'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'post'</span><span class="token1">,</span> data<span class="token1">:</span> <span class="token1">{</span>username<span class="token1">:</span> <span class="token4">'李四'</span><span class="token1">,</span>age<span class="token1">:</span> <span class="token5">20</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> <span class="token3">instance2</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'/'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'get'</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span> ``` ``` ``` <pre class="calibre13">``` <span class="token6">//把第三方模块进行封装 防止后期不更新或者难维护</span> ``` ``` 首先在根目录新建一个network文件夹 里面创建request.js文件 ``` <pre class="calibre13">``` <span class="token6">// 封装axios模块</span> <span class="token2">import</span> axios <span class="token2">from</span> <span class="token4">"axios"</span><span class="token1">;</span> <span class="token2">export</span> <span class="token2">function</span> <span class="token3">myrequest</span><span class="token1">(</span>config<span class="token1">,</span>successCallback<span class="token1">,</span>errorCallback<span class="token1">)</span> <span class="token1">{</span> <span class="token6">//1.创建axios实例</span> <span class="token2">const</span> instance <span class="token">=</span> axios<span class="token1">.</span><span class="token3">create</span><span class="token1">(</span><span class="token1">{</span> baseURL<span class="token1">:</span> <span class="token4">'http://httpbin.org'</span><span class="token1">,</span> timeout<span class="token1">:</span> <span class="token5">5000</span> <span class="token1">}</span><span class="token1">)</span> <span class="token3">instance</span><span class="token1">(</span>config<span class="token1">)</span> <span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> <span class="token3">successCallback</span><span class="token1">(</span>res<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span> <span class="token1">.</span><span class="token2">catch</span><span class="token1">(</span>err <span class="token">=></span> <span class="token1">{</span> <span class="token3">errorCallback</span><span class="token1">(</span>err<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span> <span class="token1">}</span> ``` ``` 使用 回调函数 (successCallback,errorCallback可自定义名字)把结果返回过去 没有使用export default 用的export function 因为怕以后不是封装的一个方法 前面需要用到的页面进行调用: ``` <pre class="calibre13">``` <span class="token2">import</span> <span class="token1">{</span>myrequest<span class="token1">}</span> <span class="token2">from</span> <span class="token4">"./network/request"</span><span class="token1">;</span> ``` ``` ``` <pre class="calibre13">``` <span class="token6">//把第三方模块进行封装 防止后期不更新或者难维护</span> <span class="token3">myrequest</span><span class="token1">(</span><span class="token1">{</span> url <span class="token1">:</span><span class="token4">'/get'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'get'</span><span class="token1">,</span> params<span class="token1">:</span> <span class="token1">{</span>username<span class="token1">:</span> <span class="token4">'张三'</span><span class="token1">,</span>age<span class="token1">:</span> <span class="token5">18</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">,</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">,</span>err <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>err<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> ``` ``` 最优方案一: request.js 源码 ``` <pre class="calibre13">``` <span class="token6">// 封装axios模块</span> <span class="token2">import</span> axios <span class="token2">from</span> <span class="token4">"axios"</span><span class="token1">;</span> <span class="token2">export</span> <span class="token2">function</span> <span class="token3">myrequest</span><span class="token1">(</span>config<span class="token1">)</span> <span class="token1">{</span> <span class="token2">return</span> <span class="token2">new</span> <span class="token3">Promise</span><span class="token1">(</span><span class="token1">(</span>resolve<span class="token1">,</span> reject<span class="token1">)</span> <span class="token">=></span> <span class="token1">{</span> <span class="token6">//1.创建axios实例</span> <span class="token2">const</span> instance <span class="token">=</span> axios<span class="token1">.</span><span class="token3">create</span><span class="token1">(</span><span class="token1">{</span> baseURL<span class="token1">:</span> <span class="token4">'http://httpbin.org'</span><span class="token1">,</span> timeout<span class="token1">:</span> <span class="token5">5000</span> <span class="token1">}</span><span class="token1">)</span> <span class="token3">instance</span><span class="token1">(</span>config<span class="token1">)</span> <span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> <span class="token3">resolve</span><span class="token1">(</span>res<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span> <span class="token1">.</span><span class="token2">catch</span><span class="token1">(</span>err <span class="token">=></span> <span class="token1">{</span> <span class="token3">reject</span><span class="token1">(</span>err<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span> <span class="token1">}</span> ``` ``` 调用界面源码: ``` <pre class="calibre13">``` <span class="token2">import</span> <span class="token1">{</span>myrequest<span class="token1">}</span> <span class="token2">from</span> <span class="token4">"./network/request"</span><span class="token1">;</span> ``` ``` ``` <pre class="calibre13">``` <span class="token6">//把第三方模块进行封装 防止后期不更新或者难维护</span> <span class="token3">myrequest</span><span class="token1">(</span><span class="token1">{</span> url <span class="token1">:</span><span class="token4">'/get'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'get'</span><span class="token1">,</span> params<span class="token1">:</span> <span class="token1">{</span>username<span class="token1">:</span> <span class="token4">'张三'</span><span class="token1">,</span>age<span class="token1">:</span> <span class="token5">18</span><span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token2">catch</span><span class="token1">(</span>err <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>err<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span> ``` ``` # axios 请求拦截器 ``` <pre class="calibre13">``` <span class="token6">// 挂载axios 拦截器 过滤请求</span> axios<span class="token1">.</span>interceptors<span class="token1">.</span>request<span class="token1">.</span><span class="token3">use</span><span class="token1">(</span>config <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>config<span class="token1">)</span> config<span class="token1">.</span>headers<span class="token1">.</span>Authorization <span class="token">=</span> window<span class="token1">.</span>sessionStorage<span class="token1">.</span><span class="token3">getItem</span><span class="token1">(</span><span class="token4">'token'</span><span class="token1">)</span> <span class="token6">// 在最后必须return config</span> <span class="token2">return</span> config <span class="token1">}</span><span class="token1">)</span> ``` ``` # 传递数据给java ``` <pre class="calibre14">``` <span class="token2">import</span> Vue <span class="token2">from</span> <span class="token4">'vue'</span> <span class="token2">import</span> App <span class="token2">from</span> <span class="token4">'./App.vue'</span> <span class="token2">import</span> router <span class="token2">from</span> <span class="token4">'./router'</span> <span class="token2">import</span> store <span class="token2">from</span> <span class="token4">'./store'</span> <span class="token2">import</span> axios <span class="token2">from</span> <span class="token4">'axios'</span> Vue<span class="token1">.</span>config<span class="token1">.</span>productionTip <span class="token">=</span> <span class="token5">false</span> <span class="token2">new</span> <span class="token3">Vue</span><span class="token1">(</span><span class="token1">{</span> router<span class="token1">,</span> store<span class="token1">,</span> render<span class="token1">:</span> h <span class="token">=></span> <span class="token3">h</span><span class="token1">(</span>App<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">$mount</span><span class="token1">(</span><span class="token4">'#app'</span><span class="token1">)</span> <span class="token6">// 创建axios实例</span> <span class="token2">const</span> instance <span class="token">=</span> axios<span class="token1">.</span><span class="token3">create</span><span class="token1">(</span><span class="token1">{</span> <span class="token6">// baseURL: 'api',</span> timeout<span class="token1">:</span> <span class="token5">5000</span> <span class="token1">}</span><span class="token1">)</span> <span class="token2">const</span> param <span class="token">=</span> <span class="token2">new</span> <span class="token3">URLSearchParams</span><span class="token1">(</span><span class="token1">)</span> <span class="token6">// param.append('levyId', '34156')</span> <span class="token6">// http://mer.bjlinggong.com/trans-business/clientBusiness/common.do</span> <span class="token6">// http://api.youfupingtai.com/pctrans-business/clientBusiness/common.do</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'daxiongUrl'</span><span class="token1">,</span> <span class="token4">'https://apiservice.daxiongys.com/clientBusiness/common.do'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'priKey'</span><span class="token1">,</span> <span class="token4">'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAK8Nig8CP02X2qW2W6hs2XKRe/5x3EBDeT76q3caRlF1AvXRPuTG2yP1yDOIDR+Lb8hoHTLbWZ35undaYU8a+1g5yBmSPLbi5xtMNjIqNcn16TYp6qmdAGDQ923QEo1DEyKLczZk2lQBHhdQ7vrcAGzI4DsS4xdm6fr5FJ9cKkzTAgMBAAECgYEAqxS+YuC9YWYRyHaqqbaH5dKNriU1LpFDA+wUe7hwFNgY5olzwD8gmMpyuPo0aSnrO5+VOcjqktwoAtGP3LHwBbGukHCKMp7Dw1g6Rbac/4EXXsj2Z3hKxlm3MWo7Z4SgHAZ8PURuQtu8WRR3zCdZMORqxdbOUV8EqpjIORs+9aECQQDZ3GMFGHccYprYr1X6zlxXVOU75GHTWIMclbE9mzcFhmhaO2Jj1QW2BNxwI4RxA/6PphPZQc4BKTGxTb3NF43JAkEAzbKtWqaG1go4ihxV5wy4+/V7EEPYukputZlBt+njbQ7e/DHHIaEPGkzDMT2MBTx1prwlikU40CZZM7/Om5ljuwJAHZeoA5stIrfqHKDEZwr81Af+E0KUXybYuFtE9f9NW/zD0+3ZEYJwAidq4fiRFuDaBR0j+RDNMK8txs2uiFs4sQJAeIymm+HMU9RZnldM4MPMBZ2wKbAZa9QDXdobcbVY26lDdXmWwlapizhBjLINRWRRbw4E0iwPR62xyWo3o2kZ0QJAOO6s5fbwLlQ1CfNoafeZcmvBaHiz85YTwcKlmPcVdvXuK+wT7+b9uI5vYpdJiIywdMTMS1yJcNiHp06C/ECOkw=='</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'pubKey'</span><span class="token1">,</span> <span class="token4">'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXFtJNcCv9X+pfOz+jy4WO+7KC0tdtDGfW/XrJOFn6mTR/TpJrsLzwssTyj0hDfUla1xDCbAWlUEkzb64jsPKk9WACupLOOrnEy7NuG0O5jg36UXle+m5/uDm8B/KGV9BQmEt+EOIbl2IzNYS4GflkbCTtkbzMc+DXetl3IHM1+wIDAQAB'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'charset'</span><span class="token1">,</span> <span class="token4">'utf-8'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'apiKey'</span><span class="token1">,</span> <span class="token4">'RYUL8FOAYPZK5VPKHDSTJ2XP83LJ6NAQ'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'merId'</span><span class="token1">,</span> <span class="token4">'89900000772816245891'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'reqId'</span><span class="token1">,</span> <span class="token4">'1624605422566a1j8Htzy'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'startDate'</span><span class="token1">,</span> <span class="token4">'2021-06-25'</span><span class="token1">)</span> param<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">'endDate'</span><span class="token1">,</span> <span class="token4">'2021-06-25'</span><span class="token1">)</span> <span class="token3">instance</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> <span class="token4">'/daxiong/chongzhiQuery'</span><span class="token1">,</span> method<span class="token1">:</span> <span class="token4">'post'</span><span class="token1">,</span> data<span class="token1">:</span> param <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">then</span><span class="token1">(</span>res <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>res<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token2">catch</span><span class="token1">(</span>err <span class="token">=></span> <span class="token1">{</span> console<span class="token1">.</span><span class="token3">log</span><span class="token1">(</span>err<span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span> ``` ```