URL https://i.cnblogs.com/EditPosts.aspx?opt=1
URL url = new URL("https://i.cnblogs.com");
URL url1 = new URL(url, "EditPosts.aspx?opt=1");
System.out.println(url);//https://i.cnblogs.com
System.out.println(url1);//https://i.cnblogs.com/EditPosts.aspx?opt=1
System.out.println("URL主机名称:"+url1.getHost());//URL主机名称:i.cnblogs.com
System.out.println("URL协议:"+url1.getProtocol());//URL协议:https
System.out.println("URL端口:"+url1.getPort());//URL端口:-1
System.out.println("URL文件路径:"+url1.getPath());//URL文件路径:/iEditPosts.aspx
System.out.println("URL查询字符串:"+url1.getQuery());//URL查询字符串:opt=1
System.out.println("URL相对路径:"+url1.getRef());//URL相对路径:null
System.out.println("URL文件名:"+url1.getFile());//URL文件名:/EditPosts.aspx?opt=1
try {
//创建一个URL实例
URL url = new URL("http://www.baidu.com");
//通过URL对象的openstream方法获取一个InputStream对象
InputStream is = url.openStream();
InputStreamReader isr = new InputStreamReader(is, "utf-8");
BufferedReader br = new BufferedReader(isr);
File bd = new File(".../index.jsp");
PrintWriter pw = new PrintWriter(bd);
//按行读取 获取
access_token
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxd65107df4acf0a81&secret=1cc78b3caf6f7e509dbffe710b1e1cd9 String urlNameString = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxd65107df4acf0a81&secret=1cc78b3caf6f7e509dbffe710b1e1cd9";
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.out.println(key + "—>" + map.get(key)); }
// 定义 BufferedReader输入流来读取URL的响应
BufferedReader in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
String result ="";
while ((line = in.readLine()) != null) {
result += line;
}
if (in != null) {
in.close();
}
return result; /** result 返回的json串
{
"access_token": "19_pNVNyZVX5WgtPdFarp5epawu7S-0hJTv1nvQuDJTjcUaCS_gotVa_7_-eoLhPgs2K2eKZRXuEtuONJYrW4SH3qFKhLl1-QApZ57ZqtapADJcwD6uREzmEusulyUTPHjAEAWSK",
"expires_in": 7200
}
*/
access_token
;
String s = br.readLine();
while(s!=null){
pw.print(s);
pw.flush();
s=br.readLine();
}
//关闭相关资源
pw.close();
br.close();
isr.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
URL https://i.cnblogs.com/EditPosts.aspx?opt=1的更多相关文章
- 20135306黄韧[2.72 2.77 3.70](http://i.cnblogs.com/EditPosts.aspx?opt=1)
2.72 A.size_t是无符号整数,因此左边都会先转换为无符号整数,它肯定是大于等于0的. B.判断条件改为 if(maxbytes > 0 && maxbytes > ...
- 一.定时任务详解https://i.cnblogs.com/EditPosts.aspx
定时任务的详解 h每小时运行 d每天运行 w每周运行 m每个月运行 中毒时查看系统定时任务是否有病毒的脚本. crontab -l 查看用户的定时任务 crontab -e 进入编辑界面增加 ...
- [二次编码,数据类型补充以及各种坑]https://i.cnblogs.com/EditPosts.aspx?postid=11184330
数据类型补充 str:不可变数据类型 1.capitalize首字母大写 name="song" n=name.capitalize() print(n) Song 2.title ...
- 网页中动态嵌入PDF文件/在线预览PDF内容https://www.cnblogs.com/xgyy/p/6119459.html
#网页中动态嵌入PDF文件/在线预览PDF内容# 摘要:在web开发时我们有时会需要在线预览PDF内容,在线嵌入pdf文件: 问题1:如何网页中嵌入PDF: 在网页中: 常用的几种PDF预览代码片段如 ...
- https://www.cnblogs.com/soundcode/p/4174410.html
https://www.cnblogs.com/soundcode/p/4174410.html 1.首先要在服务器端新建一个网站axpx页 然后再网站的后台写代码获取winform传过来的文件名. ...
- Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml
解决方法来源:http://www.cnblogs.com/kaka-bing/archive/2012/10/31/2747490.html 问题描述: 使用Android SDK Manager检 ...
- HBASE学习d端口master:16010(java操作hbase)https://www.cnblogs.com/junrong624/p/7323483.html
HBase提示已创建表,但是list查询时,却显示表不存在. https://blog.csdn.net/liu16659/article/details/80216085 下载网址 http://a ...
- 复选框、单选框样式自定义(https://www.cnblogs.com/freedom-feng/p/11346396.html)
复选框.单选框样式自定义(https://www.cnblogs.com/freedom-feng/p/11346396.html)复选框html内容如下:<input type="c ...
- Bootstrap-table 使用总结 转载https://www.cnblogs.com/laowangc/p/8875526.html
一.什么是Bootstrap-table? 在业务系统开发中,对表格记录的查询.分页.排序等处理是非常常见的,在Web开发中,可以采用很多功能强大的插件来满足要求,且能极大的提高开发效率,本随笔介绍这 ...
随机推荐
- linux学习笔记-shell-script相关知识
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 一.shell script的执行方法 条件:shell脚本文件必须具备可读可执行权限 1.直接命令执行 (1)使用绝对路径执行 ...
- vue安装element-ui和px2rem的细节
1.按需引入element-ui vue脚手架搭建完成之后,可以到element-ui官网进行npm 安装: npm i element-ui -S 如果是完整引入可以按照官网一步一步做即可完成:这里 ...
- 当桌面的快捷方式图标左下角出现一个X(叉)的时候应该怎么去掉
win+r打开运行,然后复制粘贴如下命令就OK辣 cmd /k reg delete "HKEY_CLASSES_ROOT\lnkfile" /v IsShortcut /f &a ...
- layui topbar图标(即返回顶部)未显示的解决方法
在自己搭建纯html模板的时候,遇到了topbar无法显示的问题,搜了社区都没啥有用的解决方法,于是引用了util.js的源文件,发现用dom变量未获取到正确的scrollTop值,经过反复测试,把这 ...
- 每秒生成一千万个【可视有序】分布式ID的简单方案
去年做了一个产品,会经常导入导出大量的外部数据,这些数据的ID有的是GUID类型,有的是字符串,也有的是自增.GUID类型没有顺序,结果要排序得借助其它业务字段,整体查询效率比较低:字符串ID本来是用 ...
- Android 解析标准的点击第三方文件管理器中的视频的intent
解析标准的第三方视频intent private List<String> mCurPlayList = new ArrayList<String>(); private in ...
- git rebase 使用详解
rebase 假设你现在基于远程分支"origin",创建一个叫"mywork"的分支. $ git checkout -b mywork origin 现 ...
- Linux & Windows 环境下 RabbitMQ 安装与基本配置
索引: 目录索引 参看代码 GitHub: rabbitmq.txt 一.Linux (DeepinOS) 环境 .安装: sudo apt install rabbitmq-server .进入目录 ...
- 【转载】FPGA算法映射要点
近期一直在学习利用FPGA完成算法的定点运算,转载些相关的博客方面回顾查找.本博文原文链接为:https://blog.csdn.net/u013989284/article/details/7899 ...
- windows搭建golang环境
由于墙的存在,很多网址无法下载,推荐https://studygolang.com/dl去下载. windows需要配置几个环境变量,我是下载的压缩文件,所以需要自己配置,通过安装程序安装的应该不需要 ...