url格式不正确,可能有"www.baidu.com"    "这个不能有

// 下载pdf
public void downpdf(String URL, String fileName) {
try {
// byte[] data = jsonStr.getBytes(); java.net.URL url = new java.net.URL(URL);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url
.openConnection(); conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);// 设置连接超时时间为5秒
conn.setReadTimeout(20 * 1000);// 设置读取超时时间为20秒
// 使用 URL 连接进行输出,则将 DoOutput标志设置为 true
conn.setDoOutput(true); conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
// 如果请求响应码是200,则表示成功
if (conn.getResponseCode() == 200) {
InputStream stream = conn.getInputStream();
FileOutputStream fos = null;
BufferedInputStream bis = null;
// HttpURLConnection httpUrl = null;
// URL url = null;
int BUFFER_SIZE = 1024;
byte[] buf = new byte[BUFFER_SIZE];
int size = 0;
bis = new BufferedInputStream(stream);
// //建立文件
fos = new FileOutputStream(fileName);
// //保存文件
while ((size = bis.read(buf)) != -1)
fos.write(buf, 0, size);
// fos.close();
bis.close();
// httpUrl.disconnect();
}
conn.disconnect();// 断开连接
} catch (Exception e) {
System.out.println(e.getMessage());
} }

java后台调用url无协议的更多相关文章

  1. java后台调用url

    版权声明:本文为博主牟云飞原创文章,未经博主同意不得转载. https://blog.csdn.net/myfmyfmyfmyf/article/details/32690757 QXOutStrea ...

  2. 获取ip ,百度地图坐标点 和 在 后台调用 url()

        protected  void getip()         {             string ips = HttpContext.Current.Request.UserHostA ...

  3. 解决Jsp与Java后台之间url传值中文乱码问题

    JSP页面中,由JavaScript拼接url时,对于中文名称变量应该加上encodeURIComponent方法,对中文进行十六进制编码. 例如: url = /com/xxx/B.jsp?chin ...

  4. java后台调用HttpURLConnection类模拟浏览器请求(一般用于接口调用)

    项目开发中难免遇到外部接口的调用,小生今天初次接触该类,跟着API方法走了一遍,如有不对的地方,还请哆哆指正,拜谢! 1 package com.cplatform.movie.back.test; ...

  5. Java后台调用gcc编译C语言代码

    想做一个能够在线编译代码运行的平台,Java和SQL已经支持了,因为是用Java写的后台,所以Java和SQL挺容易就实现了,做到支持C的时候就卡住了,网上搜了一下这种帖子好像很少. 我采取的办法是就 ...

  6. java后台调用http请求

    1:代码   @Value("${sms.username}")  可以将sms.properties配置文件中的值注入到username //这种方式是将sms.properti ...

  7. md5签名加密(用于java 后台调用短信平台接口实现发短信)

    MD5Util 方法 package com.funcanteen.business.action.pay.util; import java.security.MessageDigest; publ ...

  8. java后台调用文件上传接口

    借鉴:https://blog.csdn.net/yjclsx/article/details/70675057 /** * 调用流程上传文件接口上传文件 * @param url * @param ...

  9. java后台获取URL带参demo

    URL:http://aos.wall.youmi.net/v2/check_fb_sig?order=YM130402cygr_UTb42&app=30996ced018a2a5e& ...

随机推荐

  1. System.Linq.Enumerable 中的方法 Aggregate 函数

      语法: public static TSource Aggregate<TSource>( this IEnumerable<TSource> source, Func&l ...

  2. CentOS7 安装 net-speeder 提升 VPS 网络性能

    参考:http://blog.csdn.net/u010027419/article/details/46129639 1.安装依赖库 先安装epel源 rpm -Uvh http://dl.fedo ...

  3. VC++常用函数

    // 获取文件运行路径 void GetAppFilePath(const CString& strProjectName) { TCHAR szFileName[MAX_PATH]; HMO ...

  4. LEETCODE —— Binary Tree的3 题 —— 3种非Recursive遍历

    Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' valu ...

  5. python学习之python开发环境搭建

    Python简介 Python是一种面向对象.解释型计算机程序设计语言.Python语法简洁而清晰,具有丰富和强大的类库等等众多的特性,这是来自百度百科的介绍,在百度百科还能看到它的更详细的介绍信息, ...

  6. Python之路,day4-Python基础

    1.集合2.元组 只读列表,只有count,index2个方法3.字典key-value对 1.特性 2.查询速度快,比列表快python中的hash在同一程序下值相同python字典中的hash只有 ...

  7. rake :You have already activated rake 10.1.0

    rake aborted! You have already activated rake 10.1.0, but your Gemfile requires rake 10.0.3. Using b ...

  8. IIS7下使用4.0框架集成模式URLRewriter重写中文URL乱码问题

    解决方法: 1 url中中文先通过Server.UrlEncode编码 2 修改网站编码 3.更改URLRewriter.net中源码 找到RewriterEngine类中 private strin ...

  9. javascript 数组去重 unique

    晚上无事,偶然看到这么个小测试,拿来写一写,希望大家提建议: 直接上代码: Array.prototype.unique = function (isStrict) { if (this.length ...

  10. linux下解压大于4G文件提示error: Zip file too big错误的解决办法

    error: Zip file too big (greater than 4294959102 bytes)错误解决办法.zip文件夹大于4GB,在centos下无法正常unzip,需要使用第三方工 ...