首页 > 编程知识 正文

restful接口开发实例(java调用第三方接口方法流程)

时间:2023-05-05 05:25:21 阅读:68199 作者:4935

要求:如何在程序中调用外部API接口以获取程序所需的对象

解决方法:使用RestTemplate.exchange ()方法

代码如下。

@postmapping(/test ) ) responsebodypublicstringtest ) requestparammapstring,Object params ) resttemplateresttemplate //headers.add (内容类型,)应用程序/JSON ); httpentityhttpentity=newhttpentity (params,headers ); rest template.getmessage converters ().set (1,newstringhttpmessageconverter ) standardcharsets.utf_8) ); //HttpMethod.Get为get请求,httpEntity为nullreturnresttemplate.exchange (' http://localhost 3360 xxxx/xx/week/lll

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