我将以下内容放入应用程序的web.xml中,以尝试禁止PUT,DELETE等:
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>PUT</http-method>
<http-method>SEARCH</http-method>
<http-method>COPY</http-method>
<http-method>MOVE</http-method>
<http-method>PROPFIND</http-method>
<http-method>PROPPATCH</http-method>
<http-method>MKCOL</http-method>
<http-method>LOCK</http-method>
<http-method>UNLOCK</http-method>
<http-method>delete</http-method>
<http-method>put</http-method>
<http-method>search</http-method>
<http-method>copy</http-method>
<http-method>move</http-method>
<http-method>propfind</http-method>
<http-method>proppatch</http-method>
<http-method>mkcol</http-method>
<http-method>lock</http-method>
<http-method>unlock</http-method>
</web-resource-collection>
<auth-constraint />
</security-constraint>
好的,所以现在:
如果我使用的方法发出请求,DELETE
则会返回403。
如果我使用的方法发出请求,delete
则会返回403。
但
如果我用的方法提出要求,DeLeTe
我会确定的!
如何使它们不区分大小写?
编辑:我正在使用C#程序对其进行测试:
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "making request";
System.Threading.Thread.Sleep(400);
WebRequest req = WebRequest.Create("http://serverurl/Application/cache_test.jsp");
req.Method = txtMethod.Text;
try
{
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
textBox1.Text = "Status: " + resp.StatusCode;
if (resp.StatusCode == System.Net.HttpStatusCode.OK)
{
WebHeaderCollection header = resp.Headers;
using (System.IO.StreamReader reader = new System.IO.StreamReader(resp.GetResponseStream(), ASCIIEncoding.ASCII))
{
//string responseText = reader.ReadToEnd();
textBox1.Text += "\r\n" + reader.ReadToEnd();
}
}
}
catch (Exception ex)
{
textBox1.Text = ex.Message;
}
}
txtMethod.Text
是一个在其中输入方法名称的文本框。当存在403时,抛出异常,该异常被捕获在catch块中。
cache_test.jsp包含:
<%
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma","no-cache");
out.print("Method used was: "+request.getMethod());
%>
你如何测试呢?
—
哈维尔·卢卡斯
@XavierLucas,将其添加到问题中
—
developerwjk
@Bob,我是在Visual C#2005 Express的.NET 2.0中完成的,没有遇到任何这些问题。它发送的正是我输入的内容。因此,他们必须在更高版本中进行更改。
—
developerwjk
@鲍勃,哈哈。Microsoft的文档是错误的/具有误导性。对于.NET 2.0版本,他们还说:“ Method属性可以设置为任何HTTP 1.1协议动词:GET,HEAD,POST,PUT,DELETE,TRACE或OPTIONS。” 但这在实践中并不受任何限制。
—
developerwjk