调用odata web服务使用jaydata.js返回401

时间:2013-06-06 14:50:36

标签: iis odata cors jaydata

我使用jaydata.js调用odata webservice,但它返回401 Unauthorized。

即使浏览到该服务并在第二个浏览器选项卡中首先手动进行身份验证,仍然会在第一个选项卡中获得401。

这是我的代码:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="Scripts/datajs-1.0.3.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.8.3.js" type="text/javascript"></script>
    <script src="Scripts/jaydata.js" type="text/javascript"></script>
    <script src="Scripts/DynamicsNav70.js" type="text/javascript"></script>
    <script src="Scripts/jaydataproviders/oDataProvider.js" type="text/javascript"></script>
    <script>
        nav = new NAV.NAV({
            name: 'oData', oDataServiceHost: 'http://XXX.cloudapp.net:7048/DynamicsNav70/OData',
            user: "XXX",
            password: "XXX"
        });

        $(document).ready(function () {
            nav.Customers.forEach(function (customer) {
                var item = "<li ><a href=#>@name</a></li>".replace("@name", customer.Name);
                $('#customers').append(item);
            });
        });

    </script>
    <title></title>
</head>
<body>
    <h1>Customers</h1>
    <ul id="customers"></ul>
</body>
</html>

这是来自浏览器的信息:

Request URL:http://XXX.cloudapp.net:7048/DynamicsNav70/OData/Customers
Request Method:OPTIONS
Status Code:401 Unauthorized
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en,nl;q=0.8
Access-Control-Request-Headers:accept, maxdataserviceversion, origin, dataserviceversion
Access-Control-Request-Method:GET
Cache-Control:max-age=0
Connection:keep-alive
Host:XXX.cloudapp.net:7048
Origin:http://localhost:50793
Referer:http://localhost:50793/jaydata.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
Response Headersview source
Content-Length:0
Date:Thu, 06 Jun 2013 14:43:12 GMT
Server:Microsoft-HTTPAPI/2.0
WWW-Authenticate:Negotiate

在这个问题上我是一个完全的菜鸟,所以任何有关解决方案或更好地理解问题的建议都可能有所帮助

0 个答案:

没有答案