HTTP请求的细节
2011-10-13 22:20
225 查看
1、
Refresh:服务器通过这个头,告诉浏览器隔多长时间刷新一次
代码 如下:response.setHeader("Refresh", "2;http://www.baidu.com");
2、
Content-Type: 服务器通过这个头,告诉浏览器回送数据的类型
比如要回送一个图片类型的,代码如下 :
InputStream is=new FileInputStream("D:\\Users\\renhaili\\Workspaces\\MyEclipse 9\\renhaili\\images\\1.jpg");
response.setHeader("Content-Type", "image/jpeg");
OutputStream os=response.getOutputStream();
byte n[]=new byte[1024];
int flag=0;
while((flag=is.read(n))!=-1){
os.write(n,0,flag);
}
os.close();
is.close();
3、
Content-Disposition: 服务器通过这个头,告诉浏览器以下载方式打开数据
比如说要下载一个图片,代码 就是把第2条的这行代码:response.setHeader("Content-Type", "image/jpeg");换成response.setHeader("Content-Disposition", "attachment;filename=a.jpg");
嗯,就这样!
Refresh:服务器通过这个头,告诉浏览器隔多长时间刷新一次
代码 如下:response.setHeader("Refresh", "2;http://www.baidu.com");
2、
Content-Type: 服务器通过这个头,告诉浏览器回送数据的类型
比如要回送一个图片类型的,代码如下 :
InputStream is=new FileInputStream("D:\\Users\\renhaili\\Workspaces\\MyEclipse 9\\renhaili\\images\\1.jpg");
response.setHeader("Content-Type", "image/jpeg");
OutputStream os=response.getOutputStream();
byte n[]=new byte[1024];
int flag=0;
while((flag=is.read(n))!=-1){
os.write(n,0,flag);
}
os.close();
is.close();
3、
Content-Disposition: 服务器通过这个头,告诉浏览器以下载方式打开数据
比如说要下载一个图片,代码 就是把第2条的这行代码:response.setHeader("Content-Type", "image/jpeg");换成response.setHeader("Content-Disposition", "attachment;filename=a.jpg");
嗯,就这样!
相关文章推荐
- http你不得不知道的那些事(六)--请求响应细节
- 【java细节】Java用HttpURLConnection实现Http、restful请求
- Android 网络请求框架android-async-http的一个细节问题(org.apache.http.client.CircularRedirectException异常)
- http 请求 细节
- HTTP中请求与转发的细节
- HTTP请求的细节
- HTTP请求的细节——消息头
- 后台编写HttpWebRequest的POST请求,必须注意的一个小细节
- 两种HTTP请求方法:GET和POST
- [Java]Http请求的工具类
- HTTP请求报文和响应报文
- Android HTTP实例 使用GET方法和POST方法发送请求
- HTTP详解(2)-请求、响应、缓存
- 电商项目---Okhttp网络请求及单列模式
- 几个http请求相关的函数 HttpWebRequest: Post , Get ; PostAndRedirect
- HTTP请求模型
- Android基础入门教程——7.1.2 Android Http请求头与响应头的学习
- HttpServlet类的请求与响应
- Http请求超时的一种处理方法
- Android基础入门教程——7.1.4 Android HTTP请求方式-HttpClient