http协议-配置与调用

Http协议:

                   1)http协议: 对浏览器客户端和服务器端之间数据传输的格式规范。

                   2)http请求:浏览器->服务器端

                                     格式:

                                               请求行(请求方式(GET/POST) 请求资源(URI) http协议版本(http1.1))

                                               请求头(键值对形式存在。 host、user-agent、referer)

                                               一个空行

                                               实体内容(POST提交的参数)

                                     HttpServletRequest对象: 请求对象。获取请求信息。

                                     请求行:request.getMethod()   request.getRequestURI/getRequestURL()  request.getProtocol();

                                     请求头: request.getHeader("name")    request.getHeaderNames() 

                                     实体内容: request.getInputStream()

 

                                     获取参数数据:(GET或POST)

                                                        request.getParameter("name")  一个值的参数

                                                        request.getParameterValues("name"); 多个值的参数

                                                        request.getParameterNames()    所有参数

                                                       

                   3)http响应: 服务器->浏览器端

                                     格式:

                                               响应行(http协议版本 状态码 描述)

                                                        常用的状态码: 200   302  404   500

                                               响应头( location(结合302状态码完成请求重定向功能)、 refresh(定时刷新)、content-type、content-disiposition(以下载方式打开))

                                               一个空行

                                               实体内容

                                     HttpServletResponse对象: 响应对象。设置响应信息。

                                               响应行: response.setStatus();

                                               响应头: response.setHeader("name","value")

                                               实体内容:

                                                                 (PrintWriter) response.getWriter().writer(); 字符内容

                                                          (OutputStream)response.getOutputStream().writer();  字节内容

posted @ 2017-11-27 22:03  6NULL9  阅读(587)  评论(0编辑  收藏  举报