2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Windows.Web.Http.HttpClientの認証ダイアログを抑制する。

Last updated at Posted at 2016-11-29

Windows.Web.Http.HttpClientでBasic認証に失敗したときにダイアログが出てきて面食らったので。

var client = new HttpClient();
var req = new HttpRequestMessage(HttpMethod.Post, new Uri("https://hoge.hoge/hoge"));
req.Headers.Authorization = new HttpCredentialsHeaderValue("Basic", CredentialString);

var responese = await client.SendRequestAsync(req);

みたいなコードで認証に失敗すると、認証ダイアログが出る。
AuthDialog.PNG

HttpBaseProtocolFilterクラスのAllowUIプロパティをfalseにして、HttpClientのコンストラクタに渡せばOK。

var filter = new HttpBaseProtocolFilter();
filter.AllowUI = false;
var client = new HttpClient(filter);
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?