报这种错误可能是远程服务器没有配置Http激活
这个配置在服务器管理器中,找到“添加角色和功能(Add Roles and Features Wizard)->功能(Features)”,进行修改
这个错误,代表你所访问的网页进行了身份判断?你是不是提交了数据到那个页面?如果是post数据的话,你试下我的那个方法。
private const string UserAgent = "Mozilla/5.0 (WindowsUWindows NT 5.1en-USrv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"
public static string PostData(string url,string data)
{
// Convert to bytes
string strReturn = ""
try
{
byte[] obtPostData = Encoding.UTF8.GetBytes(data)
HttpWebRequest orqRequest = (HttpWebRequest)WebRequest.Create(url)
orqRequest.Timeout = 3000
orqRequest.Method = "POST"
orqRequest.UserAgent = UserAgent
//orqRequest.Referer = LoginRefererUrl
orqRequest.ContentType = "application/x-www-form-urlencoded"
orqRequest.ContentLength = obtPostData.Length
orqRequest.AllowAutoRedirect = false
// Add post data to request
Stream stream
using (stream = orqRequest.GetRequestStream())
{
stream.Write(obtPostData, 0, obtPostData.Length)
}
HttpWebResponse orsResponse = (HttpWebResponse)orqRequest.GetResponse()
using (Stream responseStream = orsResponse.GetResponseStream())
{
using (StreamReader streamRead = new StreamReader(responseStream, Encoding.UTF8))
{
strReturn = streamRead.ReadToEnd()
}
}
}
catch(Exception e)
{
//throw new Exception(e.Message)
}
return strReturn
}
tomcat默认就是不允许PUT和DELETE的
如何配置Tomcat支持HTTP Delete和Put 方法
在tomcat web.xml文件中配置org.apache.catalina.servlets.DefaultServlet的
<init-param>
<param-name>readonly</param-name>
<param-value>false</param-value>
</init-param>readonly参数默认是true,即不允许delete和put操作,所以通过XMLHttpRequest对象的put或者delete方法访问就会报告http 403错误。为REST服务起见,应该设置该属性为false。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)