public async Task GetAsync_ServerNeedsAuthAndNoCredential_StatusCodeUnauthorized()
        {
            using (var client = new HttpClient())
            {
                Uri uri = HttpTestServers.BasicAuthUriForCreds(Username, Password);
                HttpResponseMessage response = await client.GetAsync(uri);

                Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
            }
        }
        public async Task GetAsync_ServerNeedsAuthAndSetCredential_StatusCodeOK()
        {
            var handler = new HttpClientHandler();

            handler.Credentials = _credential;
            using (var client = new HttpClient(handler))
            {
                Uri uri = HttpTestServers.BasicAuthUriForCreds(Username, Password);
                HttpResponseMessage response = await client.GetAsync(uri);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
示例#3
0
        public void GetAsync_CredentialIsCredentialCacheUriRedirect_HttpStatusCodeOK()
        {
            Uri uri             = HttpTestServers.BasicAuthUriForCreds(Username, Password);
            Uri redirectUri     = HttpTestServers.RedirectUriForCreds(Username, Password);
            var credentialCache = new CredentialCache();

            credentialCache.Add(uri, "Basic", _credential);

            using (var handler = new HttpClientHandler())
            {
                handler.Credentials = credentialCache;
                var client   = new HttpClient(handler);
                var response = client.GetAsync(uri).Result;
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
示例#4
0
        public async Task GetAsync_AllowAutoRedirectTrue_RedirectToUriWithParams_RequestMsgUriSet()
        {
            var handler = new HttpClientHandler();

            handler.AllowAutoRedirect = true;
            Uri targetUri = HttpTestServers.BasicAuthUriForCreds(secure: false, userName: Username, password: Password);

            using (var client = new HttpClient(handler))
            {
                Uri uri = HttpTestServers.RedirectUriForDestinationUri(secure: false, destinationUri: targetUri, hops: 1);
                _output.WriteLine("Uri: {0}", uri);
                using (HttpResponseMessage response = await client.GetAsync(uri))
                {
                    Assert.Equal(targetUri, response.RequestMessage.RequestUri);
                }
            }
        }
        public async Task GetAsync_CredentialIsCredentialCacheUriRedirect_StatusCodeOK()
        {
            Uri uri             = HttpTestServers.BasicAuthUriForCreds(Username, Password);
            Uri redirectUri     = HttpTestServers.RedirectUriForCreds(Username, Password);
            var credentialCache = new CredentialCache();

            credentialCache.Add(uri, "Basic", _credential);

            var handler = new HttpClientHandler();

            handler.Credentials = credentialCache;
            using (var client = new HttpClient(handler))
            {
                HttpResponseMessage response = await client.GetAsync(redirectUri);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
示例#6
0
        public async Task GetAsync_CredentialIsCredentialCacheUriRedirect_StatusCodeOK()
        {
            Uri uri         = HttpTestServers.BasicAuthUriForCreds(secure: false, userName: Username, password: Password);
            Uri redirectUri = HttpTestServers.RedirectUriForCreds(secure: false, userName: Username, password: Password);

            _output.WriteLine(uri.AbsoluteUri);
            _output.WriteLine(redirectUri.AbsoluteUri);
            var credentialCache = new CredentialCache();

            credentialCache.Add(uri, "Basic", _credential);

            var handler = new HttpClientHandler();

            handler.Credentials = credentialCache;
            using (var client = new HttpClient(handler))
            {
                using (HttpResponseMessage response = await client.GetAsync(redirectUri))
                {
                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                }
            }
        }