在Windows Mobile中利用WebRequest下载文件并获得响应头的信息信息
来源:互联网 发布:如何练好英语知乎 编辑:程序博客网 时间:2024/05/19 17:57
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using System.Net;namespace DownloadFile{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnGet_Click(object sender, EventArgs e) { Uri u = new Uri(txtUrl.Text); Download(u, System.Environment.GetFolderPath(Environment.SpecialFolder.Personal)/* 此处获得我的文档的路径 */); } private void Download(Uri address, string localPath) { string filename = "test.txt"; WebRequest request = WebRequest.Create(address); //perform the GET request WebResponse response = request.GetResponse(); //get stream containing received data Stream s = response.GetResponseStream(); //open filestream for the output file FileStream fs = new FileStream(Path.Combine(localPath, filename), FileMode.Create, FileAccess.Write); //copy until all data is read 标准的缓存读取格式 byte[] buffer = new byte[1024]; int bytesRead = s.Read(buffer, 0, buffer.Length); while (bytesRead > 0) { fs.Write(buffer, 0, bytesRead); bytesRead = s.Read(buffer, 0, buffer.Length); } //close both streams fs.Close(); s.Close(); response.Close(); MessageBox.Show("ok"); } private void btnHead_Click(object sender, EventArgs e) { System.Net.HttpWebRequest hwr = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(txtUrl.Text); hwr.Method = "HEAD"; System.Net.WebResponse response = hwr.GetResponse(); string[] str = response.Headers.AllKeys; foreach (string temp in str) { this.listBox1.Items.Add("key="+temp+" length="+response.Headers[temp]); } } private void menuItem1_Click(object sender, EventArgs e) { Application.Exit(); } }}
0 0
- 在Windows Mobile中利用WebRequest下载文件并获得响应头的信息信息
- Java下载网络文件时获取响应头文件信息
- servlet 文件下载头信息的添加
- 在Java中获得文件的描述信息
- php下载文件头信息
- 在mapper中获得inputsplit的信息
- 在mapper中获得inputsplit的信息
- 设置下载信息的头信息
- HTTP响应头信息
- HTTP响应头信息
- HTTP响应头信息
- 获取响应头信息
- 响应头信息详解
- HTTP 响应头信息
- HTTP 响应头信息
- Http响应头信息
- 转:利用WebRequest登录网站,抓取信息
- windows oid 利用SNMP获得主机信息
- C二进制打开文件
- HDU 1142 欢迎参加——每周六晚的BestCoder(有米!) A Walk Through the Forest
- 职责链模式
- 初入android驱动开发之字符设备(五-定时器)
- 主表,从表【MySql】
- 在Windows Mobile中利用WebRequest下载文件并获得响应头的信息信息
- NSURLSession和AFNetWorking配合使用
- HTML5定稿了,为什么原生App世界将被颠覆
- 2D Deconvolution for Image Reconstruction
- Git+Hexo搭建静态博客网站
- Linux如何查看进程、杀死进程、启动进程等常用命令
- DTE DCE的含义和判断方法
- 自定义Spring动态代理类型
- 使用Git上传本地项目文件带代码托管平台