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开发中,可以采用很多功能强大的插件来满足要求,且能极大的提高开发效率,本随笔介绍这 ...
随机推荐
- ORM的增删查
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; usin ...
- html中节点类型
常用的节点有元素节点.属性节点.文本节点.注释节点.文档节点 来看例子: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transition ...
- 20, CSS 定义选择器
1. ID 与类 2. 层叠 3. 分组 4. 继承 5. 上下文选择器 6. 子类选择器 7. 其他选择器 8. 结构与注释 20.1 ID 与类 选择器是用于控制页面设计的样式.即 ID 选择器何 ...
- 使用Canvas绘制简单的时钟控件
Canvas是HTML5新增的组件,它就像一块幕布,可以用JavaScript在上面绘制各种图表.动画等. 没有Canvas的年代,绘图只能借助Flash插件实现,页面不得不用JavaScript和F ...
- 点击checkbox后,$(this).attr('checked')得到的值不会发生改变
这两天遇到一个问题,就是在点击checkbox后,$(this).attr('checked')得到的值要么是undefined,要么是checked,同一个表单一直点击却一点都不会发生改变,调试了一 ...
- Salesforce 小知识:大量“子记录”的处理方法
大量"子记录"的存放 例子:系统中导入了很多"联系人"(Contact)记录,它们没有具体所属的"客户"(Account)记录.那么我们就要 ...
- Rxjs常用operators
本文使用的是angular6内置的rxjs,版本号为6.3.3 concat 通过顺序地发出多个 Observables 的值将它们连接起来,一个接一个的. 参数: 名称 类型 属性 描述 other ...
- 如何给win7自带的截图工具设置快捷键
win7自带的截图工具很好,很强大,比从网上下载的截图工具好用多了,很少会出现问题.但是它能不能像QQ截图工具一样可以使用快捷键呢?今天小编和大家分享下心得,希望能够给你的工作带来快捷. 工具/原料 ...
- (办公)SpringBoot和swagger2的整合.
因为开发项目的接口需要给app,小程序测试,所以用swagger. 1.pom.xml: <dependency><!--添加Swagger依赖 --> <groupId ...
- 修改vue element Transfer 穿梭框里内容区的宽度
<template> <el-transfer v-model="value1" :data="data"></el-transf ...