我对网络编程比较陌生。 我有一个Windows窗体试图通过ajax和java脚本与Web服务进行通信。 我的表单有以下代码,
string sURL = <<URL>>;
HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(sURL);
//Modify request properties
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.AllowAutoRedirect = false;
request.AllowWriteStreamBuffering = false;
string sRequestData = JsonConvert.SerializeObject(new GetSessionInfo() { UserName = "xxxxxx", Database = "xxxxxx", Module = "xxxxxx" }.ToString());
StreamWriter sWriter = new StreamWriter(request.GetRequestStream());
sWriter.Write(sRequestData);
sWriter.Close();
try
{
//Extract the response
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
if (response == null)
return false;
StreamReader responcestream = new StreamReader(response.GetResponseStream());
string ResponseData = responcestream.ReadToEnd();
responcestream.Close();
return true;
}
catch
{
throw;
}
我的index.html文件如下所示
function Session()
{
$.ajax({
type: "POST",
url: "/ProcessRequestFromEasyOrder",
data : JSON.stringify({ user:"****", Database:"****", module:"****"}),
contentType: "application/json; charset=utf-8",
dataType: "application/json",
async: true,
cache: false,
cors: true,
success:function(data){
alert(data);
}
});
}
目前,我可以通过浏览器硬编码参数来调用Web服务方法。但是,当我尝试通过我的窗体表格时,它总是返回我(405)方法不允许。 有人可以帮我回答以下问题,
我在.NET 4.5上 非常感谢你的帮助!