如何禁止DELETE、PUT、OPTIONS、TRACE、HEAD等协议访问应用程序

原文:http://linder.iteye.com/blog/735435


简介

 WebDAV (Web-based Distributed Authoring and Versioning)是基于 HTTP 1.1 的一个通信协议。它为 HTTP 1.1 添加了一些扩展(就是在 GET、POST、HEAD 等几个 HTTP 标准方法以外添加了一些新的方法),使得应用程序可以直接将文件写到 Web Server 上,并且在写文件时候可以对文件加锁,写完后对文件解锁,还可以支持对文件所做的版本控制。这个协议的出现极大地增加了 Web 作为一种创作媒体对于我们的价值。基于 WebDAV 可以实现一个功能强大的内容管理系统或者配置管理系统。
     现在主流的WEB服务器一般都支持WebDAV,使用WebDAV的方便性,呵呵,就不用多说了吧,用过VS.NET开发ASP.NET应用的朋友就应该知道,新建/修改WEB项目,其实就是通过WebDAV+FrontPage扩展做到的,下面我就较详细的介绍一下,WebDAV在tomcat中的配置。

 

如何禁止DELETE、PUT、OPTIONS、TRACE、HEAD等协议访问应用程序应用程序呢?

解决方法

第一步:修改应用程序的web.xml文件的协议

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns="http://java.sun.com/xml/ns/j2ee"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"  
  5.     version="2.4">  

第二步:在应用程序的web.xml中添加如下的代码即可

Xml代码   收藏代码
  1.   <security-constraint>  
  2.    <web-resource-collection>  
  3.       <url-pattern>/*</url-pattern>  
  4.       <http-method>PUT</http-method>  
  5. <http-method>DELETE</http-method>  
  6. <http-method>HEAD</http-method>  
  7. <http-method>OPTIONS</http-method>  
  8. <http-method>TRACE</http-method>  
  9.    </web-resource-collection>  
  10.    <auth-constraint>  
  11.    </auth-constraint>  
  12.  </security-constraint>  
  13.  <login-config>  
  14.    <auth-method>BASIC</auth-method>  
  15.  </login-config>  

 重新部署程序,重启tomcat即可完成

如果用户要验证既可以将POST和GET也添加在其中,重新部署并启动tomcat即可看到效果

以上的代码添加到某一个应用中,也可以添加到tomcat的web.xml中,区别是添加到某一个应用只对某一个应用有效如果添加到tomcat的web.xml中,则对tomcat下所有的应用有效。

关于web.xml的详细配置见

http://www.blogjava.net/baoyaer/articles/107428.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. GET方法 ```csharp using System.Net.Http; // 创建HttpClient对象 HttpClient client = new HttpClient(); // 发送GET请求 HttpResponseMessage response = await client.GetAsync("http://www.example.com"); string responseBody = await response.Content.ReadAsStringAsync(); ``` 2. POST方法 ```csharp using System.Net.Http; using System.Text; using System.Text.Json; // 创建HttpClient对象 HttpClient client = new HttpClient(); // 准备POST请求数据 var data = new { name = "John", age = 30 }; var jsonContent = JsonSerializer.Serialize(data); var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); // 发送POST请求 HttpResponseMessage response = await client.PostAsync("http://www.example.com", content); string responseBody = await response.Content.ReadAsStringAsync(); ``` 3. PUT方法 ```csharp using System.Net.Http; using System.Text; using System.Text.Json; // 创建HttpClient对象 HttpClient client = new HttpClient(); // 准备PUT请求数据 var data = new { name = "John", age = 30 }; var jsonContent = JsonSerializer.Serialize(data); var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); // 发送PUT请求 HttpResponseMessage response = await client.PutAsync("http://www.example.com", content); string responseBody = await response.Content.ReadAsStringAsync(); ``` 4. DELETE方法 ```csharp using System.Net.Http; // 创建HttpClient对象 HttpClient client = new HttpClient(); // 发送DELETE请求 HttpResponseMessage response = await client.DeleteAsync("http://www.example.com"); string responseBody = await response.Content.ReadAsStringAsync(); ``` 5. HEAD方法 ```csharp using System.Net.Http; // 创建HttpClient对象 HttpClient client = new HttpClient(); // 发送HEAD请求 HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Head, "http://www.example.com"); HttpResponseMessage response = await client.SendAsync(request); ``` 6. OPTIONS方法 ```csharp using System.Net.Http; // 创建HttpClient对象 HttpClient client = new HttpClient(); // 发送OPTIONS请求 HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Options, "http://www.example.com"); HttpResponseMessage response = await client.SendAsync(request); ``` 7. TRACE方法 ```csharp using System.Net.Http; // 创建HttpClient对象 HttpClient client = new HttpClient(); // 发送TRACE请求 HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Trace, "http://www.example.com"); HttpResponseMessage response = await client.SendAsync(request); ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值