如何将身份验证标头传递给OData服务 [英] How to pass authentication header to OData Service

查看:86
本文介绍了如何将身份验证标头传递给OData服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循

如果我禁用身份验证并请求数据,则可以正常工作.我找不到任何有关如何使用"datajs"发送身份验证头信息的示例代码(当与OData.Request和/或OData.Read一起使用时).

有人可以帮我吗?

解决方案

如果按照帖子中的描述使用基本身份验证,则可以使用OData.request的request参数来传递用户名和密码.

http://datajs.codeplex.com/wikipage? title = datajs%20OData%20API#OData.request

您可以这样写:

OData.request({requestUri:"...", user:"user", password:"secret"}, function (data) { ... });

请注意,这不适用于跨域AJAX.

希望这会有所帮助!

I am following authentication method described at http://blogs.msdn.com/b/astoriateam/archive/2010/07/21/odata-and-authentication-part-6-custom-basic-authentication.aspx

I am able to consume service using ASP.NET (not a problem at all). Now I would like to create a plain HTML page and access the service using "OData Javascript Library" (datajs).

If I disable authentication and request for data, it works fine. I could not find any sample code on how to send authentication header information using "datajs" (when used with OData.Request and/or OData.Read).

Can anyone help me on this?

解决方案

If you're using basic authentication as described in the post, you can use the request parameter of OData.request to pass in the username and password.

http://datajs.codeplex.com/wikipage?title=datajs%20OData%20API#OData.request

You could write something like:

OData.request({requestUri:"...", user:"user", password:"secret"}, function (data) { ... });

Note that this will not work with cross-domain AJAX.

Hope this helps!

这篇关于如何将身份验证标头传递给OData服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆