首页 > 编程知识 正文

接口可以双向传参,http怎么对接接口

时间:2023-05-06 09:21:35 阅读:36775 作者:4113

package com.bbb.aaa.util; importorg.Apache.http.http entity; importorg.Apache.http.http status; importorg.Apache.http.client.config.request config; importorg.Apache.http.client.methods.closeablehttpresponse; importorg.Apache.http.client.methods.request builder; importorg.Apache.http.impl.client.closeablehttpclient; importorg.Apache.http.impl.client.http clients; importorg.Apache.http.util.entity utils; import java.nio.charset.Charset; import java.util.Map; publicclassaaautil {私有身份验证lintrequest _ time out=3* 1000; //设置请求超时10秒privatestaticfinalintconnect _ time out=5* 1000; //连接超时时间隐私保护inalintso _ time out=10 * 1000; //数据传输超时私有身份验证字符串编码=' utf-8 '; 隐私保护客户端; static { requestconfigrequestconfig=request config.custom ().setconnecttimeout (connect _ time out ).setconnectionrequt client=http clients.custom (.setdefaultrequestconfig (request config ).setmaxconntotal ) ) 50 ).build ); } publicstaticstringquerykdwlinfo (字符串路径、映射、字符串映射) returnsend (请求构建器. post (路径、映射) ) } publicstaticstringsend (requestbuilderrequestbuilder,MapString,String paramsMap ) requestbuilder.setcharset ) charset 参数映射!=null(for ) map.entrystring,string param : params map.entryset ) ) requestbuilder.addparameter ) param.get ker } try { response=client.execute (请求构建器. build (); if (response.get statusline (.get status code )==HttpStatus.SC_OK ) httpentity=response.get entity ) )。 实体!=null (responsetext=entity utils.tostring (entity,ENCODING ) ); }}catch(exceptione ) { e.printStackTrace ); //正式项目中为日志打印(finally ) try (response.close ); }catch(exceptione ) { e.printStackTrace ); //在正式项目中请更改为log打印} } } return responseText; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。