jquery - Connecting to Cross Domain Dynamics CRM Web API (Unauthorized)
问题描述
I'm having a problem connecting to the Dynamics CRM Web API.
I'm trying to connect to the Web API from an external .NET Core page, using javascript but I keep getting the 401 Unauthorized error
. It seems a cross domain problem. The error is:
No 'Access-Control-Allow-Origin' header is present on the requested resource
Basically I'm at the domain domain1.com
, and I need to run a web api call at domain2.com
using javascript.
So how can I achieve that? I do not want my user to be prompted to authenticate, but I need to manage that by the code.
Also, I'm not using Azure to authenticate but I'm using ADFS.
This is my code:
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: "https://crm.anuv.com.br/api/data/v8.2/EntityDefinitions(LogicalName='account')",
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
XMLHttpRequest.setRequestHeader("Accept", "application/json");
XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
},
async: false,
success: function (data, textStatus, xhr) {
var results = data;
var jsonResult = JSON.parse(data);
alert(jsonResult.Attributes.length);
},
error: function (xhr, textStatus, errorThrown) {
alert(errorThrown);
}
});
解决方案
推荐阅读
- c - 以下实用程序的宏与函数的用法
- c - 编写一个程序来检查一个数字是否是阿姆斯壮和神奇的,或者两者都不是使用函数
- swift - 使用 DisclosureGroup 时的 SwiftUI List 与 ForEach
- android - 在通过 Android WebRTC 流式传输视频时拍摄高分辨率(本地)照片?
- ruby - 如何检查 nil 并比较 != nil on Hashes?
- javascript - Next.js 得到混淆的 API 响应
- r - 自动扩展网页的折叠部分以在 R 中进行网页抓取
- php - 运行 composer install 时内存不足
- java - 将十进制int转换为二进制
- python - 如何在matplotlib中修改数字堆叠在一起的x轴