예제 #1
0
        public void Authentication_UseMultiInterfaceStreamContent_Success()
        {
            RemoteInvoke(async useManagedHandlerString =>
            {
                string username           = "******";
                string password           = "******";
                Uri uri                   = Configuration.Http.BasicAuthUriForCreds(secure: false, userName: username, password: password);
                HttpClientHandler handler = CreateHttpClientHandler(useManagedHandlerString);
                handler.Credentials       = new NetworkCredential(username, password);

                using (var client = new HttpClient(handler))
                {
                    byte[] postData = Encoding.UTF8.GetBytes("This is data to post.");
                    var stream      = new MultiInterfaceReadOnlyStream(postData);
                    var content     = new MultiInterfaceStreamContent(stream);

                    using (HttpResponseMessage response = await client.PostAsync(uri, content))
                    {
                        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                        string responseContent = await response.Content.ReadAsStringAsync();
                    }
                }

                return(SuccessExitCode);
            }, UseManagedHandler.ToString()).Dispose();
        }
예제 #2
0
        public void Authentication_UseMemoryStreamNotVisibleBufferContent_Success()
        {
            RemoteExecutor.Invoke(async(useSocketsHttpHandlerString, useHttp2String) =>
            {
                string username           = "******";
                string password           = "******";
                Uri uri                   = Configuration.Http.RemoteHttp11Server.BasicAuthUriForCreds(userName: username, password: password);
                HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandlerString, useHttp2String);
                handler.Credentials       = new NetworkCredential(username, password);

                using (HttpClient client = CreateHttpClient(handler, useHttp2String))
                {
                    byte[] postData = Encoding.UTF8.GetBytes("This is data to post.");
                    var stream      = new MemoryStream(postData, 0, postData.Length, false, false);
                    var content     = new MultiInterfaceStreamContent(stream);

                    using (HttpResponseMessage response = await client.PostAsync(uri, content))
                    {
                        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                        string responseContent = await response.Content.ReadAsStringAsync();
                    }
                }

                return(RemoteExecutor.SuccessExitCode);
            }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
        }
예제 #3
0
        public void Authentication_UseMultiInterfaceNonRewindableStreamContent_Throws()
        {
            RemoteExecutor.Invoke(async(useSocketsHttpHandlerString, useHttp2String) =>
            {
                string username           = "******";
                string password           = "******";
                Uri uri                   = Configuration.Http.RemoteHttp11Server.BasicAuthUriForCreds(userName: username, password: password);
                HttpClientHandler handler = CreateHttpClientHandler(useSocketsHttpHandlerString, useHttp2String);
                handler.Credentials       = new NetworkCredential(username, password);

                using (HttpClient client = CreateHttpClient(handler, useHttp2String))
                {
                    byte[] postData = Encoding.UTF8.GetBytes("This is data to post.");
                    var stream      = new MultiInterfaceNonRewindableReadOnlyStream(postData);
                    var content     = new MultiInterfaceStreamContent(stream);

                    await Assert.ThrowsAsync <HttpRequestException>(() => client.PostAsync(uri, content));
                }
            }, UseSocketsHttpHandler.ToString(), UseHttp2.ToString()).Dispose();
        }
예제 #4
0
        public void Authentication_UseMultiInterfaceNonRewindableStreamContent_Throws()
        {
            RemoteInvoke(async useManagedHandlerString =>
            {
                string username           = "******";
                string password           = "******";
                Uri uri                   = Configuration.Http.BasicAuthUriForCreds(secure: false, userName: username, password: password);
                HttpClientHandler handler = CreateHttpClientHandler(useManagedHandlerString);
                handler.Credentials       = new NetworkCredential(username, password);

                using (var client = new HttpClient(handler))
                {
                    byte[] postData = Encoding.UTF8.GetBytes("This is data to post.");
                    var stream      = new MultiInterfaceNonRewindableReadOnlyStream(postData);
                    var content     = new MultiInterfaceStreamContent(stream);

                    await Assert.ThrowsAsync <HttpRequestException>(() => client.PostAsync(uri, content));
                }

                return(SuccessExitCode);
            }, UseManagedHandler.ToString()).Dispose();
        }