关于调用第三方接口开发里
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
post的连接方式里上面两行代码是否必要存疑。看了网上的相关接口方法里,很少涉及到这个。所以下面几个链接作为备用。
链接: java调用第三方http接口.
链接: 关于PrintWriter out = response.getWriter()的使用及注意事项.
重要的一点【关闭连接】,上面或者说网上关于调用接口例子里几乎都是错误用法!下面是Java如何正确关闭IO流
finally {
try {
if (null != fr) {
fr.close();
}
} catch (IOException e) {
throw new RuntimeException("关闭失败");
}
try {
if (null != fw) {
fw.close();
}
} catch (IOException e) {
throw new RuntimeException("关闭失败");
}
}
具体参考链接: Java如何正确关闭IO流.
另外,一篇优秀的博文关于”springboot/web项目优秀的后端接口体系“
具体参考链接: springboot/web项目优秀的后端接口体系.