JSON 応答を送信する REST API に接続しようとしています。ブラウザに URL をコピーして貼り付けると、ブラウザにユーザー名とパスワードを入力するためのポップアップが表示されます。
ユーザー名とパスワード (Active Directory ID とパスワード) を入力すると、サービスは JSON 応答を送信します。 HTTP リクエストとレスポンス
しかし、コードから接続しようとすると、次のエラーが返されます
{StatusCode: 401、ReasonPhrase: 'Unauthorized'、バージョン: 1.1、コンテンツ: System.Net.Http.StreamContent、Headers: { Keep-Alive: timeout=15、max=100 Connection: Keep-Alive Date: Wed, 20 Apr 2016 11:38:45 GMT サーバー: Apache WWW-Authenticate: Basic realm="Login using your AD-ENT credentials, but do not do your ID with the domain"
Content-Length: 455 Content-Type: text/html; charset=iso-8859-1 }}
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(@"http://pro.abc.com/services/");
var authData = string.Format("{0}:{1}","username", "password");
var authHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(authData));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue);
HttpResponseMessage response = await client.GetAsync("reportpro/reports/11824");