http https 下载
来源:互联网 发布:数据交换前置机怎么做 编辑:程序博客网 时间:2024/05/17 15:37
readLen = inputStream.read(temp)) 返回-1
public void downRss2() {
long time1 = System.currentTimeMillis();
InputStream inputStream = null;
FileOutputStream fos = null;
String filePath = path + "/voa/RSSlink.xml";
HttpClient httpClient = new DefaultHttpClient();
HttpGet get = new HttpGet(baseUrl);
try {
fos = new FileOutputStream(filePath);
// FakeX509TrustManager.allowAllSSL();
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpProtocolParams.setUseExpectContinue(params, true);
HttpProtocolParams
.setUserAgent(
params,
"Mozilla/5.0(Linux;U;Android 2.2.1;en-us;Nexus One Build.FRG83) "
+ " AppleWebKit/553.1(KHTML,like Gecko) Version/4.0 Mobile Safari/533.1");
// 超时设置
/* 从连接池中取连接的超时时间 */
ConnManagerParams.setTimeout(params, 1000);
/* 连接超时 */
HttpConnectionParams.setConnectionTimeout(params, 2000);
/* 请求超时 */
HttpConnectionParams.setSoTimeout(params, 4000);
// 设置我们的HttpClient支持HTTP和HTTPS两种模式
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
schReg.register(new Scheme("https", SSLSocketFactory
.getSocketFactory(), 443));
HttpResponse httpResponse = httpClient.execute(get);
int responseCode = httpResponse.getStatusLine().getStatusCode();
Log.d("zdj", "responseCode = " + responseCode);
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
Log.d("zdj", "entity is not null");
inputStream = entity.getContent();
byte[] temp = new byte[512];
int readLen = 0;
while ((readLen = inputStream.read(temp)) > 0) {
writelog("readlen : " + String.valueOf(readLen));
fos.write(temp, 0, readLen);
}
}
} catch (IOException e) {
e.printStackTrace();
dialog("downRss");
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
if (fos != null) {
fos.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/***************************************************************************************/
File rss = new File(path + "/voa/RSSlink.xml");
if (!rss.exists()) {
String str = "RSSLink.xml下载失败";
writelog(str);
}
/***************************************************************************************/
long time2 = System.currentTimeMillis();
String str = String.valueOf((time2 - time1) / 1000);
writelog("RSSlink.xml文件下载时间: " + str);
}
- http https 下载
- https下载文件http header 设置
- 文件下载支持http和https
- 基于http 和 https的文件下载
- 【RLIB】C++调用HttpRequest 、HttpResponse下载远程HTTP/HTTPS资源
- 使用HTTP/HTTPS向服务器上传、下载文件
- SpringMVC下http和https路径下的文件下载
- http -> https
- HTTP HTTPs
- HTTP & HTTPs
- HTTP、HTTPS
- http https
- Http & Https
- HTTP/HTTPS
- http https
- HTTP、HTTPS
- 下载编译安装Apache HTTP Server 2.4.23以及配置HTTP/HTTPS反向代理
- 解决Http或Https中下载中文文件乱码和无法下载问题
- C语言的变量声明在其它语句之前
- DotNet注意点:System.Timer和Thread.timer和Form.timer
- C++调用C函数
- iphone开发收藏3
- 操作系统好书
- http https 下载
- C++覆盖成员变量、类变量
- C++覆盖成员变量、类变量
- MFC多文档子窗体切换时,依附于框架对话框参数的更新问题
- 操作系统疑问
- output_buffering详细介绍
- C语言变量类型的本质
- [Linux] Can not connect to X server
- Oracle 创建函数的权限