常用的 Http Response Code代码

100 Continue 初始的请求已经接受,客户应当继续发送请求的其余部分。(HTTP 1.1新)

101 Switching Protocols 服务器将遵从客户的请求转换到另外一种协议(HTTP 1.1新)

200 OK 一切正常,对GET和POST请求的应答文档跟在后面。

201 Created 服务器已经创建了文档,Location头给出了它的URL。

202 Accepted 已经接受请求,但处理尚未完成。

203 Non-Authoritative Information 文档已经正常地返回,但一些应答头可能不正确,因为使用的是文档的拷贝(HTTP 1.1新)。

204 No Content 没有新文档,浏览器应该继续显示原来的文档。如果用户定期地刷新页面,而Servlet可以确定用户文档足够新,这个状态代码是很有用的。

205 Reset Content 没有新的内容,但浏览器应该重置它所显示的内容。用来强制浏览器清除表单输入内容(HTTP 1.1新)。

206 Partial Content 客户发送了一个带有Range头的GET请求,服务器完成了它(HTTP 1.1新)。

300 Multiple Choices 客户请求的文档可以在多个位置找到,这些位置已经在返回的文档内列出。如果服务器要提出优先选择,则应该在Location应答头指明。

301 Moved Permanently 客户请求的文档在其他地方,新的URL在Location头中给出,浏览器应该自动地访问新的URL。

302 Found 类似于301,但新的URL应该被视为临时性的替代,而不是永久性的。注意,在HTTP1.0中对应的状态信息是“Moved Temporatily”。
出现该状态代码时,浏览器能够自动访问新的URL,因此它是一个很有用的状态代码。

注意这个状态代码有时候可以和301替换使用。例如,如果浏览器错误地请求http://host/~user(缺少了后面的斜杠),有的服务器返回301,有的则返回302。

严格地说,我们只能假定只有当原来的请求是GET时浏览器才会自动重定向。请参见307。

303 See Other 类似于301/302,不同之处在于,如果原来的请求是POST,Location头指定的重定向目标文档应该通过GET提取(HTTP 1.1新)。

304 Not Modified 客户端有缓冲的文档并发出了一个条件性的请求(一般是提供If-Modified-Since头表示客户只想比指定日期更新的文档)。服务器告诉客户,原来缓冲的文档还可以继续使用。

305 Use Proxy 客户请求的文档应该通过Location头所指明的代理服务器提取(HTTP 1.1新)。

307 Temporary Redirect 和302(Found)相同。许多浏览器会错误地响应302应答进行重定向,即使原来的请求是POST,即使它实际上只能在POST请求的应答是303时才能重定向。由于这个原因,HTTP 1.1新增了307,以便更加清除地区分几个状态代码:当出现303应答时,浏览器可以跟随重定向的GET和POST请求;如果是307应答,则浏览器只能跟随对GET请求的重定向。(HTTP 1.1新)

400 Bad Request 请求出现语法错误。

401 Unauthorized 客户试图未经授权访问受密码保护的页面。应答中会包含一个WWW-Authenticate头,浏览器据此显示用户名字/密码对话框,然后在填写合适的Authorization头后再次发出请求。

403 Forbidden 资源不可用。服务器理解客户的请求,但拒绝处理它。通常由于服务器上文件或目录的权限设置导致。

404 Not Found 无法找到指定位置的资源。这也是一个常用的应答。

405 Method Not Allowed 请求方法(GET、POST、HEAD、Delete、PUT、TRACE等)对指定的资源不适用。(HTTP 1.1新)

406 Not Acceptable 指定的资源已经找到,但它的MIME类型和客户在Accpet头中所指定的不兼容。(HTTP 1.1新)

407 Proxy Authentication Required 类似于401,表示客户必须先经过代理服务器的授权。(HTTP 1.1新)

408 Request Timeout 在服务器许可的等待时间内,客户一直没有发出任何请求。客户可以在以后重复同一请求。(HTTP 1.1新)

409 Conflict 通常和PUT请求有关。由于请求和资源的当前状态相冲突,因此请求不能成功。(HTTP 1.1新)

410 Gone 所请求的文档已经不再可用,而且服务器不知道应该重定向到哪一个地址。它和404的不同在于,返回407表示文档永久地离开了指定的位置,而404表示由于未知的原因文档不可用。(HTTP 1.1新)

411 Length Required 服务器不能处理请求,除非客户发送一个Content-Length头。(HTTP 1.1新)

412 Precondition Failed 请求头中指定的一些前提条件失败。(HTTP 1.1新)

413 Request Entity Too Large 目标文档的大小超过服务器当前愿意处理的大小。如果服务器认为自己能够稍后再处理该请求,则应该提供一个Retry-After头。(HTTP 1.1新)

414 Request URI Too Long URI太长。(HTTP 1.1新)

416 Requested Range Not Satisfiable 服务器不能满足客户在请求中指定的Range头。(HTTP 1.1新)

500 Internal Server Error 服务器遇到了意料不到的情况,不能完成客户的请求。

501 Not Implemented 服务器不支持实现请求所需要的功能。例如,客户发出了一个服务器不支持的PUT请求。

502 Bad Gateway 服务器作为网关或者代理时,为了完成请求访问下一个服务器,但该服务器返回了非法的应答。

503 Service Unavailable 服务器由于维护或者负载过重未能应答。例如,Servlet可能在数据库连接池已满的情况下返回503。服务器返回503时可以提供一个Retry-After头。

504 Gateway Timeout 由作为代理或网关的服务器使用,表示不能及时地从远程服务器获得应答。(HTTP 1.1新)

505 HTTP Version Not Supported 服务器不支持请求中所指明的HTTP版本。(HTTP 1.1新) 
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
此书中有几个常用实例系统 <%@language=vbscript codepage=936 %> <% option explicit response.buffer=true %> <!--#include file="Connections/connSoft.asp" --> <% Dim Rs1__MMColParam Rs1__MMColParam = "False" If (Request("MM_EmptyValue") <> "") Then Rs1__MMColParam = Request("MM_EmptyValue") End If %> <% Dim Rs1 Dim Rs1_numRows Set Rs1 = Server.CreateObject("ADODB.Recordset") Rs1.ActiveConnection = MM_connSoft_STRING Rs1.Source = "SELECT * FROM Soft WHERE Deleted = " + Replace(Rs1__MMColParam, "'", "''") + "" Rs1.CursorType = 0 Rs1.CursorLocation = 2 Rs1.LockType = 1 Rs1.Open() Rs1_numRows = 0 %> <% Dim Repeat1__numRows Dim Repeat1__index Repeat1__numRows = 10 Repeat1__index = 0 Rs1_numRows = Rs1_numRows + Repeat1__numRows %> <% ' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables Dim Rs1_total Dim Rs1_first Dim Rs1_last ' set the record count Rs1_total = Rs1.RecordCount ' set the number of rows displayed on this page If (Rs1_numRows < 0) Then Rs1_numRows = Rs1_total Elseif (Rs1_numRows = 0) Then Rs1_numRows = 1 End If ' set the first and last displayed record Rs1_first = 1 Rs1_last = Rs1_first + Rs1_numRows - 1 ' if we have the correct record count, check the other stats If (Rs1_total <> -1) Then If (Rs1_first > Rs1_total) Then Rs1_first = Rs1_total End If If (Rs1_last > Rs1_total) Then Rs1_last = Rs1_total End If If (Rs1_numRows > Rs1_total) Then Rs1_numRows = Rs1_total End If End If %> <% ' *** Recordset Stats: if we don't know the record count, manually count them If (Rs1_total = -1) Then ' count the total records by iterating through the recordset Rs1_total=0 While (Not Rs1.EOF) Rs1_total = Rs1_total + 1 Rs1.MoveNext Wend ' reset the cursor to the beginning If (Rs1.CursorType > 0) Then Rs1.MoveFirst Else Rs1.Requery End If ' set the number of rows displayed on this page If (Rs1_numRows < 0 Or Rs1_numRows > Rs1_total) Then Rs1_numRows = Rs1_total End If ' set the first and last displayed record Rs1_first = 1 Rs1_last = Rs1_first + Rs1_numRows - 1 If (Rs1_first > Rs1_total) Then Rs1_first = Rs1_total End If If (Rs1_last > Rs1_total) Then Rs1_last = Rs1_total End If End If %> <% Dim MM_paramName %> <% ' *** Move To Record and Go To Record: declare variables Dim MM_rs Dim MM_rsCount Dim MM_size Dim MM_uniqueCol Dim MM_offset Dim MM_atTotal Dim MM_paramIsDefined Dim MM_param Dim MM_index Set MM_rs = Rs1 MM_rsCount = Rs1_total MM_size = Rs1_numRows MM_uniqueCol = "" MM_paramName = "" MM_offset = 0 MM_atTotal = false MM_paramIsDefined = false If (MM_paramName <> "") Then MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "") End If %> <% ' *** Move To Record: handle 'index' or 'offset' parameter if (Not MM_paramIsDefined And MM_rsCount <> 0) then ' use index parameter if defined, otherwise use offset parameter MM_param = Request.QueryString("index") If (MM_param = "") Then MM_param = Request.QueryString("offset") End If If (MM_param <> "") Then MM_offset = Int(MM_param) End If ' if we have a record count, check if we are past the end of the recordset If (MM_rsCount <> -1) Then If (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' past end or move last If ((MM_rsCount Mod MM_size) > 0) Then ' last page not a full repeat region MM_offset = MM_rsCount - (MM_rsCount Mod MM_size) Else MM_offset = MM_rsCount - MM_size End If End If End If ' move the cursor to the selected record MM_index = 0 While ((Not MM_rs.EOF) And (MM_index < MM_offset Or MM_offset = -1)) MM_rs.MoveNext MM_index = MM_index + 1 Wend If (MM_rs.EOF) Then MM_offset = MM_index ' set MM_offset to the last possible record End If End If %> <% ' *** Move To Record: if we dont know the record count, check the display range If (MM_rsCount = -1) Then ' walk to the end of the display range for this page MM_index = MM_offset While (Not MM_rs.EOF And (MM_size < 0 Or MM_index < MM_offset + MM_size)) MM_rs.MoveNext MM_index = MM_index + 1 Wend ' if we walked off the end of the recordset, set MM_rsCount and MM_size If (MM_rs.EOF) Then MM_rsCount = MM_index If (MM_size < 0 Or MM_size > MM_rsCount) Then MM_size = MM_rsCount End If End If ' if we walked off the end, set the offset based on page size If (MM_rs.EOF And Not MM_paramIsDefined) Then If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then If ((MM_rsCount Mod MM_size) > 0) Then MM_offset = MM_rsCount - (MM_rsCount Mod MM_size) Else MM_offset = MM_rsCount - MM_size End If End If End If ' reset the cursor to the beginning If (MM_rs.CursorType > 0) Then MM_rs.MoveFirst Else MM_rs.Requery End If ' move the cursor to the selected record MM_index = 0 While (Not MM_rs.EOF And MM_index < MM_offset) MM_rs.MoveNext MM_index = MM_index + 1 Wend End If %> <% ' *** Move To Record: update recordset stats ' set the first and last displayed record Rs1_first = MM_offset + 1 Rs1_last = MM_offset + MM_size If (MM_rsCount <> -1) Then If (Rs1_first > MM_rsCount) Then Rs1_first = MM_rsCount End If If (Rs1_last > MM_rsCount) Then Rs1_last = MM_rsCount End If End If ' set the boolean used by hide region to check if we are on the last record MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount) %> <% ' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters Dim MM_keepNone Dim MM_keepURL Dim MM_keepForm Dim MM_keepBoth Dim MM_removeList Dim MM_item Dim MM_nextItem ' create the list of parameters which should not be maintained MM_removeList = "&index=" If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName & "=" End If MM_keepURL="" MM_keepForm="" MM_keepBoth="" MM_keepNone="" ' add the URL parameters to the MM_keepURL string For Each MM_item In Request.QueryString MM_nextItem = "&" & MM_item & "=" If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item)) End If Next ' add the Form variables to the MM_keepForm string For Each MM_item In Request.Form MM_nextItem = "&" & MM_item & "=" If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item)) End If Next ' create the Form + URL string and remove the intial '&' from each of the strings MM_keepBoth = MM_keepURL & MM_keepForm If (MM_keepBoth <> "") Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1) End If If (MM_keepURL <> "") Then MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1) End If If (MM_keepForm <> "") Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1) End If ' a utility function used for adding additional parameters to these strings Function MM_joinChar(firstItem) If (firstItem <> "") Then MM_joinChar = "&" Else MM_joinChar = "" End If End Function %> <% ' *** Move To Record: set the strings for the first, last, next, and previous links Dim MM_keepMove Dim MM_moveParam Dim MM_moveFirst Dim MM_moveLast Dim MM_moveNext Dim MM_movePrev Dim MM_urlStr Dim MM_paramList Dim MM_paramIndex Dim MM_nextParam MM_keepMove = MM_keepBoth MM_moveParam = "index" ' if the page has a repeated region, remove 'offset' from the maintained parameters If (MM_size > 1) Then MM_moveParam = "offset" If (MM_keepMove <> "") Then MM_paramList = Split(MM_keepMove, "&") MM_keepMove = "" For MM_paramIndex = 0 To UBound(MM_paramList) MM_nextParam = Left(MM_paramList(MM_paramIndex), InStr(MM_paramList(MM_paramIndex),"=") - 1) If (StrComp(MM_nextParam,MM_moveParam,1) <> 0) Then MM_keepMove = MM_keepMove & "&" & MM_paramList(MM_paramIndex) End If Next If (MM_keepMove <> "") Then MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1) End If End If End If ' set the strings for the move to links If (MM_keepMove <> "") Then MM_keepMove = Server.HTMLEncode(MM_keepMove) & "&" End If MM_urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "=" MM_moveFirst = MM_urlStr & "0" MM_moveLast = MM_urlStr & "-1" MM_moveNext = MM_urlStr & CStr(MM_offset + MM_size) If (MM_offset - MM_size < 0) Then MM_movePrev = MM_urlStr & "0" Else MM_movePrev = MM_urlStr & CStr(MM_offset - MM_size) End If %> <html> <head> <title>软件管理</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="GENERATOR" content="Microsoft FrontPage 3.0"> <link rel="stylesheet" type="text/css" href="Style.css"> <style type="text/css"> <!-- body,td,th { font-family: 宋体; } --> </style></head> <body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0"> <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border"> <tr class="topbg"> <td height="22" align="center"><strong>上 传 软 件 管 理</strong></td> </tr> </table> <br> <table width='100%' border="0" cellpadding="0" cellspacing="0"> <tr> <form name="myform" method="Post" action="Admin_SoftDel.asp" onSubmit="return ConfirmDel();"> <td><table class="border" border="0" cellspacing="1" width="100%" cellpadding="0"> <tr class="title" height="22"> <td width="20" align="center" height="22"><strong>ID</strong></td> <td width="138" align="center" ><strong>软件名称</strong></td> <td width="84" align="center" ><strong>软件大小</strong></td> <td width="84" align="center" ><strong>软件类型</strong></td> <td width="127" align="center" ><strong>授权方式</strong></td> <td width="114" align="center" ><strong>软件语言</strong></td> <td width="165" align="center" ><strong>操作</strong></td> </tr> <% Dim i i = 1 While ((Repeat1__numRows <> 0) AND (NOT Rs1.EOF)) %> <tr class="tdbg" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#BFDFFF'"> <td width="20" align="center"><%= i %></td> <td><%=(Rs1.Fields.Item("SoftName").Value)%> </td> <td width="84" align="center"><%=(Rs1.Fields.Item("SoftSize").Value)%></td> <td width="84" align="center"><%=(Rs1.Fields.Item("SoftType").Value)%></td> <td width="127" align="center"><%=(Rs1.Fields.Item("CopyrightType").Value)%> </td> <td width="114" align="center"><%=(Rs1.Fields.Item("SoftLanguage").Value)%> </td> <td width="165" align="center"><a href="SetDeleted.asp?SoftID=<%=(Rs1.Fields.Item("SoftID").Value)%>&Flag=Delete">删除</a> <a href="movesoft.asp?SoftID=<%=(Rs1.Fields.Item("SoftID").Value)%>">移动到</a> <select name="select"> <option value="系统软件">系统软件</option> <option value="下载软件">下载软件</option> <option value="电子图书">电子图书</option> </select> </td> <% i = i + 1 Repeat1__index=Repeat1__index+1 Repeat1__numRows=Repeat1__numRows-1 Rs1.MoveNext() Wend %> </table> </td> </form></tr></table> <% If Not Rs1.EOF Or Not Rs1.BOF Then %> <table width="100%" border="0"> <tr> <td class="tdbg"><div align="center"><A HREF="<%=MM_moveFirst%>">首页</A> <A HREF="<%=MM_movePrev%>">上一页</A> <A HREF="<%=MM_moveNext%>">下一页</A> <A HREF="<%=MM_moveLast%>">尾页</A>  第 <%=abs(Int(-Rs1_last/10))%>页/共 <%=abs(Int(-Rs1_total/10))%>页 10条记录/页 </div></td> </tr> </table> <% End If ' end Not Rs1.EOF Or NOT Rs1.BOF %> <br> <br> </body> </html> <% Rs1.Close() Set Rs1 = Nothing %>
net的最近面试经典试题ASP.NET面试题集合 1. 简述 private、 protected、 public、 internal 修饰符的访问权限。 答 . private : 私有成员, 在类的内部才可以访问。 protected : 保护成员,该类内部和继承类中可以访问。 public : 公共成员,完全公开,没有访问限制。 internal: 在同一命名空间内可以访问。 2 .列举ASP.NET 页面之间传递值的几种方式。 答. 1.使用QueryString, 如....?id=1; response. Redirect().... 2.使用Session变量 3.使用Server.Transfer 3. 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。 答:public class MainClass { public static void Main() { Console.WriteLine(Foo(30)); } public static int Foo(int i) { if (i 0 && i <= 2) return 1; else return Foo(i -1) + Foo(i - 2); } } 4.C#中的委托是什么?事件是不是一种委托? 答 : 委托可以把一个方法作为参数代入另一个方法。 委托可以理解为指向一个函数的引用。 是,是一种特殊的委托 5.override与重载的区别 答 : override 与重载的区别。重载是方法的名称相同。参数或参数类型不同,进行多次重载以适应不同的需要 Override 是进行基类中函数的重写。为了适应需要。 6.如果在一个B/S结构的系统中需要传递变量值,但是又不能使用Session、Cookie、Application,您有几种方法进行处理? 答 : this.Server.Transfer 7.请编程遍历页面上所有TextBox控件并给它赋值为string.Empty? 答: foreach (System.Windows.Forms.Control control in this.Controls) { if (control is System.Windows.Forms.TextBox) { System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ; tb.Text = String.Empty ; } } 8.请编程实现一个冒泡排序算法? 答: int [] array = new int ; int temp = 0 ; for (int i = 0 ; i < array.Length - 1 ; i++) { for (int j = i + 1 ; j < array.Length ; j++) { if (array[j] < array) { temp = array ; array = array[j] ; array[j] = temp ; } } } 9.描述一下C#中索引器的实现过程,是否只能根据数字进行索引? 答:不是。可以用任意类型。 10.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m [Page] 答: int Num = this.TextBox1.Text.ToString() ; int Sum = 0 ; for (int i = 0 ; i < Num + 1 ; i++) { if((i%2) == 1) { Sum += i ; } else { Sum = Sum - I ; } } System.Console.WriteLine(Sum.ToString()); System.Console.ReadLine() ; 11.用.net做B/S结构的系统,您是用几层结构来开发,每一层之间的关系以及为什么要这样分层? 答:一般为3层 数据访问层,业务层,表示层。 数据访问层对数据库进行增删查改。 业务层一般分为二层,业务表观层实现与表示层的沟通,业务规则层实现用户密码的安全等。 表示层为了与用户交互例如用户添加表单。 优点: 分工明确,条理清晰,易于调试,而且具有可扩展性。 缺点: 增加成本。 12.在下面的例子里 using Sy
超 文本传输协议(HTTP)是一种为分布式,合作式,超媒体信息系统。它是一种通用的,无状态(stateless)的协议,除了应用于超文本传输外,它也 可以应用于诸如名称服务器和分布对象管理系统之类的系统,这可以通过扩展它的请求方法,错误代码和报头[47]来实现。HTTP的一个特点是数据表现形式 是可输入的和可协商性的,这就允许系统能被建立而独立于数据传输。 目录 1 引论 1.1 目的 1.2 要求 1.3 术语 1.4 总体操作 2 符号习惯和一般语法 2.1 扩充的BNF(扩充的 巴科斯-诺尔范式) 2.2基本规则 (basic rule) 3 协议参数 3.1 HTTP版本 3.2 统一资源标识符(URI) 3.2.1一般语法 3.2.2 http URL 3.2.3 URI 比较 3.3 日期/时间格式(Date/Time Formats) 3.3.1完整日期 (Full Date) 3.3.2 Delta Seconds 3.4 字符集 3.4.1丢失的字符集(Missing Charset) 3.5 内容编码(Content Codings) 3.6 传输编码 (Transfer Codings) 3.6.1块传输编码(Chunked Transfer Coding) 3.7 媒体类型(Media Type) 3.7.1规范化和文本缺省 (Canonicalization and Text Defaults) 3.7.2多部分类型(Multipart type) 3.8 产品标记 (product Tokens) 3.9 质量值(Quality Values) 3.10 语言标签 (Language Tags) 3.11 实体标签 (Entity Tags) 3.12 范围单位(Range Units) 4 HTTP消息 4.1 消息类型(Message Types) 4.2 消息头 (Message Headers) 4.3 消息主体 (Message Body) 4.4 消息的长度(Message Length) 4.5 常用头域(General Header Fields) 5 请求(Request) 5.1 请求行 (Request-Line) 5.1.1方法 (Method) 5.1.2请求URL(Request-URI) 5.2请求资源 (The Resource Identified by a Request) 5.3请求报头域 (Request Header Fields) 6 响应 (Response) 6.1 状态行 (Status-Line) 6.1.1状态码与原因短语 (Status Code and Reason Phrase) 7 实体(Entity) 7.1 实体报文域(Entity Header Fields) 7.2 实体主体(Entity Body) 7.2.1类型(Type) 7.2.2实体主体长度(Entity Length) 8 连接 8.1 持续连接(Persistent Connection)。 8.1.1目的 8.1.2总体操作 8.1.2.1 协商(Negotiation) 8.1.2.2 流水线(pilelining) 8.1.3代理服务器 (Proxy Servers) 8.1.4实际的考虑 (Practical Considerations) 8.2 消息传送要求(Message Transmission Requirements) 8.2.1持续连接与流量控制 (Persistent Connections and Flow Control) 8.2.2监视连接中出错状态的消息 8.2.3 100状态码的用途 8.2.4服务器过早关闭连接时客户端的行为 9 方法定义(Method Definitions) 9.1 安全和等幂(Idempotent)方法 9.1.1安全方法(Safe Methods) 9.1.2等幂方法(Idempotent Mehtods) 9.2 OPTIONS(选项) 9.3 GET 9.4 HEAD 9.5 POST 9.6 PUT 9.7 DELETE(删除) 9.8 TRACE 9.9 CONNECT(连接) 10.状态码定义 10.1 通知的 1xx 10.1.1 100 继续 (Continue) 10.1.2 101切换协议 (Switching Protocols) 10.2 成功 2xx 10.2.1 200 OK 10.2.2 201 已创建(Created) 10.2.3 202 接受(Accepted) 10.2.4 203 非权威信息(Non-Authoritative informatio
压缩包中含有多个文档,从了解httpclient到应用。 httpClient 1httpClint 1.1简介 HttpClient是Apache Jakarta Common下的子项目,用来提供高效的、最新的、功能丰富的支持HTTP协议的客户端编程工具包,并且它支持HTTP协议最新的版本和建议。HttpClient已经应用在很多的项目中,比如Apache Jakarta上很著名的另外两个开源项目Cactus和HTMLUnit都使用了HttpClient。 下载地址:  http://hc.apache.org/downloads.cgi 1.2特性 1. 基于标准、纯净的java语言。实现了Http1.0和Http1.1 2. 以可扩展的面向对象的结构实现了Http全部的方法(GET, POST, PUT, DELETE, HEAD, OPTIONS, and TRACE)。 3. 支持HTTPS协议。 4. 通过Http代理建立透明的连接。 5. 利用CONNECT方法通过Http代理建立隧道的https连接。 6. Basic, Digest, NTLMv1, NTLMv2, NTLM2 Session, SNPNEGO/Kerberos认证方案。 7. 插件式的自定义认证方案。 8. 便携可靠的套接字工厂使它更容易的使用第三方解决方案。 9. 连接管理器支持多线程应用。支持设置最大连接数,同时支持设置每个主机的最大连接数,发现并关闭过期的连接。 10. 自动处理Set-Cookie中的Cookie。 11. 插件式的自定义Cookie策略。 12. Request的输出流可以避免流中内容直接缓冲到socket服务器。 13. Response的输入流可以有效的从socket服务器直接读取相应内容。 14. 在http1.0和http1.1中利用KeepAlive保持持久连接。 15. 直接获取服务器发送的response code和 headers。 16. 设置连接超时的能力。 17. 实验性的支持http1.1 response caching。 18. 源代码基于Apache License 可免费获取。 1.3版本 org.apache.http.impl.client.HttpClients 与 org.apache.commons.httpclient.HttpClient目前后者已被废弃,apache已不再支持。 一般而言,使用HttpClient均需导入httpclient.jar与httpclient-core.jar2个包。 1.4使用方法与步骤 开发环境:需要 使用HttpClient发送请求、接收响应很简单,一般需要如下几步即可。 1.创建HttpClient对象。 HttpClient client = new HttpClient(); 2.创建请求方法的实例,并指定请求URL。如果需要发送GET请求,创建HttpGet对象;如果需要发送POST请求,创建HttpPost对象。 //使用GET方法,如果服务器需要通过HTTPS连接,那只需要将下面URL中的 http换成https HttpMethod method = new GetMethod("http://www.baidu.com"); //使用POST方法 HttpMethod method = new PostMethod("http://java.sun.com";); 3. 如果需要发送请求参数,可调用HttpGet、HttpPost共同的setParams(HetpParams params)方法来添加请求参数;对于HttpPost对象而言,也可调用setEntity(HttpEntity entity)方法来设置请求参数。 3.调用HttpClient对象的execute(HttpUriRequest request)发送请求,该方法返回一个HttpResponse。 client.executeMethod(method); 5. 调用HttpResponse的getAllHeaders()、getHeaders(String name)等方法可获取服务器的响应头;调用HttpResponse的getEntity()方法可获取HttpEntity对象,该对象包装了服务器的响应内容。程序可通过该对象获取服务器的响应内容。 6. 释放连接。无论执行方法是否成功,都必须释放连接 //打印服务器返回的状态 System.out.println(method.getStatusLine()); //打印返回的信息 System.out.println(method.getResponseBodyAsString(
在 Delphi 11 中,使用 TNetHTTPClient 组件发送 HTTP 请求后,您可以通过 IHTTPResponse 接口的各种属性来获取服务器的响应信息。以下是一些常用Response 参数: - `StatusCode`: 获取服务器返回的状态码,例如 200 表示成功,404 表示未找到页面等。 - `StatusText`: 获取与状态码对应的文本描述,例如 "OK" 表示成功,"Not Found" 表示未找到页面等。 - `ContentAsString`: 获取响应内容的字符串形式。 - `Headers`: 获取响应的标头信息,可以通过 Headers 属性访问特定标头字段的值。 - `ContentStream`: 获取响应内容的流形式,可以使用 TMemoryStream 或其他派生类来处理。 以下是一个示例代码,演示如何使用这些 Response 参数: ```delphi uses System.Net.HttpClient, System.Net.URLClient, System.Classes; procedure SendRequest(const URL: string); var Client: TNetHTTPClient; Response: IHTTPResponse; begin Client := TNetHTTPClient.Create(nil); try Response := Client.Get(URL); // 获取状态码和描述 ShowMessage(Format('Status Code: %d', [Response.StatusCode])); ShowMessage(Format('Status Text: %s', [Response.StatusText])); // 获取响应内容 ShowMessage('Content: ' + Response.ContentAsString); // 获取特定标头字段的值 ShowMessage(Format('Content-Type: %s', [Response.Headers['Content-Type']])); // 将响应内容保存到文件 if Response.StatusCode = 200 then begin Response.ContentStream.Position := 0; Response.ContentStream.SaveToFile('response.txt'); end; finally Client.Free; end; end; ``` 在上述代码中,我们使用 TNetHTTPClient 的 Get 方法发送 GET 请求,并使用 IHTTPResponse 接口的各种属性来获取服务器的响应信息。 您可以根据自己的需求使用适当的 Response 参数来处理响应信息。希望对您有所帮助!如果您有任何其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值