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开发中,可以采用很多功能强大的插件来满足要求,且能极大的提高开发效率,本随笔介绍这 ...
随机推荐
- javaweb登陆过滤器实现
在web.xml中配置登陆过滤器: <!-- 配置登陆过滤器 --> <filter> <filter-name>loginFilter</filter-na ...
- Dagger2源码浅析
dagger2是目前android端比较火的一款依赖注入框架,先来看下基本的用法吧: 首先提供module,类似于工厂: @Module public class ApiServiceModule { ...
- 【Intellij idea】spring中@Autowired注入失败
@Autowired注入失败失败的解决办法? 现有的解决的方案是: 打开file-settings或者ctrl+alt+s -> Editor 然后在Inspections 点击搜索栏 输入Sp ...
- mysql删除表中重复数据,只保留一个最小的id的记录
语句: delete from table1 where id not in (select minid from (select min(id) as minid from table1 group ...
- python3 正则表达式点星问号(.*?)能不能匹配换行符?不能的话应该怎么写
python3的re模块使用过程中,正则的书写遇到了一些问题,就是使用.*?能不能匹配到换行符的问题. 答案是不能. 如果在匹配过程中遇到了也没关系,加上这个语句就好: \s+
- IOS判断NSArray是否为空
场景描述:判断一个集合是否为空,如果不为空执行A,如果为空执行B Java实现方法 public void exec(){ List<String> list = this.getCont ...
- Java中console类的简单用法
Java.io.Console 只能用在标准输入.输出流未被重定向的原始控制台中使用,在 Eclipse 或者其他 IDE 的控制台是用不了的. import java.io.Console; pub ...
- 持续代码质量管理-SonarQube Scanner部署
1. SonarQube Scanner地址 上一篇文章我们安装了SonarQube-7.3,让我们可以在页面查看代码质量.但是具体的扫描工作则需要SonarQube Scanner完成. 下载页面 ...
- 2016 西普杯丶天津CTF预选赛(3/6)
哆啦A梦(图片隐写) 格式:SimCTF{ } 解:放到kail中binwalk一下(Binwalk是一个固件的分析工具,旨在协助研究人员对固件非分析,提取及逆向工程用处.简单易用,完全自动化脚本,并 ...
- 【Linux基础】查看硬件信息-CPU
1.物理CPU数:计算机上实际配置的CPU个数. //查看计算机物理CPU个数(必须先sort后uniq) cat /proc/cpuinfo | grep "physical id&quo ...