可能是由于缺少权限或者未正确传递参数所导致的。建议检查请求是否已经正确设置,并确认连接的身份验证凭据是否具有足够的权限来访问Activity Runs的数据。另外,可尝试使用较新版本的ADF REST API。
示例代码:
1.使用 Microsoft.IdentityModel.Clients.ActiveDirectory 库进行身份验证:
var authenticationContext = new AuthenticationContext(authority);
var credential = new UserCredential(userName, password);
var result = authenticationContext.AcquireToken(resourceUrl, clientId, credential);
string accessToken = result.AccessToken;
2.使用 HttpClient 发送请求:
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri(restUrl);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
HttpResponseMessage response = await client.GetAsync("activityruns");
if (response.IsSuccessStatusCode)
{
string responseContent = await response.Content.ReadAsStringAsync();
//这里可以对返回数据进行解析
}
else
{
throw new Exception($"Error Response: {response.StatusCode}");
}
}
上一篇:ADF任务修改