【问题标题】:IE 10 HTTP 401 Error on ajax POSTajax POST 上的 IE 10 HTTP 401 错误
【发布时间】:2013-03-07 01:41:17
【问题描述】:

I've been chasing down an issue 并决定对问题进行最基本的复现,希望一个简化的问题能帮助我解决这个问题。

当我在 javascript 中通过 ajax 发布到 Web 服务时收到 401。我将包含尽可能多的信息以及我尝试过的所有故障排除步骤。

我在网站的根目录上创建了一个测试页面,并尝试使用纯 JS 和 jquery 进行 ajax 调用,结果相同。我已经包含了注释掉的 jquery...

页面

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//" "http://www.w3.org/TR/html4/loose.dtd">

<head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

<script type="text/javascript">
/*$(document).ready(function() {
    $('#button').click(function() {
        var ID = 2;
        var firstname = $('#First_Name').val();
        var lastname = $('#Last_Name').val(); 

        $.ajax({
            type: 'POST',
            url: '/service/name/service.aspx/ChangeName',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            data: '{ "ID": "' + ID + '", "firstName": "' + firstname + '", "lastName": "' + lastname + '" }',
            success: function() {
                console.log('success');

            },
            error: function(d) {
                console.log(d.responseText);
            }
        });
    });
});*/

function runAjax() {
    //Create Http request depending on browser
    var xmlhttp;
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();}
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}

    xmlhttp.onreadystatechange=function(){
      if (xmlhttp.readyState==4 && xmlhttp.status==200){
        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;}
      }

    // Function to create 
    var url = "/service/name/service.aspx/ChangeName";
    xmlhttp.open("POST",url,true);
    xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    var data=JSON.stringify({ "ID": "2", "firstName": "John", "lastName": "Doe" });
    xmlhttp.send(data);
}
</script>
</head>
<body>
<div id="myDiv">
      <table width="100%" cellpadding="3" cellspacing="0">
        <tbody>
        <tr>
            <td width="34%">
                <div align="right">
                    <strong>First Name: </strong>
                </div>
            </td>
            <td>
                <div>
                    <input name="First_Name" type="text"id="First_Name" size="20">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div align="right">
                    <strong>Last Name: </strong>
                </div>
            </td>
            <td>
                <input name="Last_Name" type="text" id="Last_Name" size="20">
            </td>
        </tr>
      </tbody>
      </table>

      <div align="center">

        <input id="button" type="button" value="Update Student Details" onclick="runAjax();" style="margin:5px;">

        </div>
    </div>
</body>
</html>

现在在除 IE10 之外的所有浏览器中都可以正常工作。在 fiddler 中显示 IE 得到 401 响应

请求标头 提琴手

POST http://dev.mysite/service/name/service.aspx/ChangeName HTTP/1.1
Accept: */*
Content-Type: application/json; charset=utf-8
Referer: http://dev.mysite/test_page.html
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Connection: Keep-Alive
Content-Length: 46
DNT: 1
Host: dev.mysite
Pragma: no-cache

{"ID":"2","firstName":"John","lastName":"Doe"}

响应标头 提琴手

HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.0
jsonerror: true
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
X-Powered-By: ASP.NET
Date: Thu, 07 Mar 2013 01:12:05 GMT
Content-Length: 105
Proxy-Support: Session-Based-Authentication

我在服务器上启用了失败的请求跟踪,这是它为该调用提供给我的信息:

失败的请求日志 iis

1. -GENERAL_REQUEST_START

2。 -FILTER_START

  • FilterName - C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_filter.dll

3. -FILTER_END

4. -AspNetStart

  • ConnID - 0
  • 上下文 ID - {00000000-0000-0000-6425-0080000000BF}
  • 数据1 - 发布
  • Data2 - /service/name/service.aspx
  • 数据3 -

5. -GENERAL_REQUEST_END

  • 已发送字节数 - 359
  • BytesReceived - 440
  • HttpStatus - 401
  • HttpSubStatus - 0

通过简化 ajax 请求,我发现它不仅是 Windows 8 的问题,而且打开兼容模式也不起作用。

我已经尝试在 IIS 中禁用内核模式身份验证,我已经三次检查了 Web 服务文件夹 followed these suggestions 的权限,我什至尝试将 Web 服务放在与页面相同的目录中。所有结果都相同...非常感谢任何指导或帮助。

【问题讨论】:

    标签: ajax iis-7 http-post internet-explorer-10 http-status-code-401


    【解决方案1】:

    我知道这是一个老问题,但我遇到了这个问题,因为我遇到了类似的问题。然而,这对我有用 - 一旦我将它添加到 web.config 我停止收到 401 错误:

    <webservices>
        <protocols>
            <add name="HttpGet"></add>
            <add name="HttpPost"></add>
        </protocols>
    </webServices>
    

    【讨论】:

      【解决方案2】:

      只是好奇这是否与我遇到的问题相同。

      在 URL 的末尾添加斜杠是否可以解决 IE 10 中的问题?例如

      /service/name/service.aspx/ChangeName/
      

      而不是

      /service/name/service.aspx/ChangeName
      

      如果是这样,Fiddler 和 IE 的 Eric Lawrence 会在此解释,http://blogs.msdn.com/b/ieinternals/archive/2010/11/22/internet-explorer-post-bodies-are-zero-bytes-in-length-when-authentication-challenges-are-expected.aspx

      【讨论】:

        猜你喜欢
        • 2021-05-19
        • 1970-01-01
        • 2016-08-06
        • 2013-02-23
        • 1970-01-01
        • 2013-10-17
        • 1970-01-01
        • 2017-01-01
        • 1970-01-01
        相关资源
        最近更新 更多