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下Jenkins服务器搭建
系统环境 操作系统:CentOS6.9 java jdk:java 8 Jenkins版本:jenkins-2.78-1.1.noarch.rpm 关闭防火墙 注意:如果是基于msbuild构建.ne ...
- latex数学公式
https://khan.github.io/KaTeX/function-support.html 最近要写<具体数学>的读书笔记,发现好多数学符号不会打啊qwq.. 大于号:\geqs ...
- arcgis api 3.x for js 入门开发系列十二地图打印GP服务(附源码下载)
前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...
- SuperMap GIS资料-----云与Web端技术资料集锦
转自:http://blog.csdn.net/supermapsupport/article/details/70254484 产品白皮书 iServer产品 教学视频 许可说明 安装部署 ...
- MySQL自增列(AUTO_INCREMENT)相关知识点总结
MySQL的自增列(AUTO_INCREMENT)和其它数据库的自增列对比,有很多特性和不同点(甚至不同存储引擎.不同版本也有一些不同的特性),让人感觉有点稍微复杂.下面我们从一些测试开始,来认识 ...
- VS2017 EF本地数据库链接
1. 本地数据库连接 server name可以从链接字符串中取: (localdb)\MSSQLLocalDB 注意少写一个\. { "Logging": { "Inc ...
- Linux电源管理(9)_wakelocks【转】
1. 前言 wakelocks是一个有故事的功能. wakelocks最初出现在Android为linux kernel打的一个补丁集上,该补丁集实现了一个名称为"wakelocks&quo ...
- Linux学习历程——Centos 7 top命令
一.命令介绍 top 命令用于动态的监控进程活动与系统负载信息. 格式为 top [参数] 二.实例 直接运行top命令 top命令执行结果的前五行为系统整体的统计信息,代表含义如下: 第1行:系统时 ...
- 注册表修改computer name
修改windows server的机器名的时候,发现change按钮是disable的. 手动修改不了,用注册表regedit来修改. HKEY_LOCAL_MACHINE\SYSTEM\Curren ...
- docker-compose编排项目redis容器实现主从复制
一.pip管理工具安装 docker-compose是python项目,所以安装需要通过python下的包管理工具pip安装.一般linux服务器都会预安装有python环境,所以优先检查python ...