首页 > 编程知识 正文

第三方接口如何调用(调用第三方接口组合)

时间:2023-05-05 22:20:34 阅读:68138 作者:1222

publicstatichttpresultpostjsondata (字符串URL、映射、字符串参数、字符串图表) throws Exception{

closeablehttpclienthttpclient=http client util.create default (;

http post http post=new http post (URL;

//连接参数

listnamevaluepairlist=newarraylistnamevaluepair (;

for(map.entrystring,stringentry : params.entryset () () () ) ) ) )。

String key=entry.getKey ().toString );

String value=entry.getValue ().toString );

//System.out.println (响应内容为1: ) httpentity.getcontent );

}

字符串结果=null;

try {

result=entity utils.tostring (http entity,DEFAULT_CHARSET );

Logger.info(result );

}catch(ioexceptione ) {

throw e;

} finally {

实体utils.consume (http entity );

}

returnJSON.parseobject(result,HttpResult.class );

//return httpEntity.getContent (;

}else{

返回空值;

}

}catch(ioexceptione ) {

thrownewexception(e.getmessage ) );

}finally {

try{

//释放资源

响应!=空) {

response.close (;

}

if(http客户端!=空) {

http客户端. close (;

}

}catch(ioexceptionE1) {

throw new exception (closeablehttpresponsecloseexception );

}

}

}

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