4

I've been chasing down an issue並決定對此問題進行最基本的複製,希望簡化的問題能夠幫助我解決此問題。IE 10 HTTP 401在ajax POST上發生錯誤

我在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能正常工作。在提琴手它表明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 \框架\ v4.0.30319 \ aspnet_filter.dll

3 -FILTER_END

4。-AspNetStart

  • CONNID - 0
  • 上下文ID - {00000000-0000-0000-6425-0080000000BF}
  • 數據1 - POST
  • 數據2 - /服務/name/service.aspx
  • Data3 -

5. -GENERAL_REQUEST_END

  • BytesSent - 359
  • 與BytesReceived - 440
  • 的HTTPStatus - 401
  • HttpSubStatus - 0

通過簡化ajax請求發現的事情是,它不僅是Windows 8的問題,並且打開兼容模式也不起作用。

我已經嘗試禁用IIS中的內核模式身份驗證,我已經在Web服務文件夾上檢查了三重權限,followed these suggestions,我甚至嘗試將Web服務放在與頁面相同的目錄中。所有的結果都一樣......任何方向或協助都不勝感激。

回答

1

我知道這是一個老問題,但我來到這,因爲我是有類似的問題。這是我的工作,但是 - 一旦我將此添加到web.config我停止得到401錯誤:

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