博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java httpUtil
阅读量:4646 次
发布时间:2019-06-09

本文共 1215 字,大约阅读时间需要 4 分钟。

public class HttpUtils {    public static String getContent(String url, Map
heads, String charset, String method) throws Exception { URL httpUrl = new URL(url); HttpURLConnection httpURLConnection = (HttpURLConnection) httpUrl.openConnection(); ; // 设置报头 if (heads != null) { for (Map.Entry entry : heads.entrySet()) { httpURLConnection.setRequestProperty((String) entry.getKey(), (String) entry.getValue()); } } httpURLConnection.setRequestMethod(method); httpURLConnection.setDoInput(true); httpURLConnection.setInstanceFollowRedirects(true); httpURLConnection.connect();// 握手 String result = ""; BufferedReader in = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(), charset)); String line; while ((line = in.readLine()) != null) { result += line; } return result; } public static void main(String[] args) throws Exception { String url = ""; String ret = HttpUtils.getContent(url, null, "utf-8", "POST"); System.out.println(ret); }}

 

转载于:https://www.cnblogs.com/tengpan-cn/p/8944458.html

你可能感兴趣的文章
Elgg网站迁移指南
查看>>
素数筛法优化
查看>>
installshield 注册dll
查看>>
Sublime Text 3 及Package Control 安装(附上一个3103可用的Key)
查看>>
LTE QCI分类 QoS
查看>>
Get MAC address using POSIX APIs
查看>>
bzoj2120
查看>>
基于uFUN开发板的心率计(一)DMA方式获取传感器数据
查看>>
【dp】船
查看>>
oracle, group by, having, where
查看>>
⑥python模块初识、pyc和PyCodeObject
查看>>
object-c中管理文件和目录:NSFileManager使用方法
查看>>
Kibana:分析及可视化日志文件
查看>>
nodejs pm2使用
查看>>
cocos2d-x 3.10 PageView BUG
查看>>
装饰器的基本使用:用户登录
查看>>
CSS选择器总结
查看>>
mysql中sql语句
查看>>
head/tail实现
查看>>
sql语句的各种模糊查询语句
查看>>