예제 #1
0
        public async Task Can_post_raw_response_as_raw_JSON_HttpClient()
        {
            var httpClient = new JsonHttpClient(BaseUrl);
            var request    = new GetCustomer {
                CustomerId = 5
            };
            var response = httpClient.Post(request);

            Assert.That(response.Customer.Id, Is.EqualTo(5));

            var requestPath = request.ToPostUrl();

            string json = request.ToJson();

            response = await httpClient.PostAsync <GetCustomerResponse>(requestPath, json);

            Assert.That(response.Customer.Id, Is.EqualTo(5));

            byte[] bytes = json.ToUtf8Bytes();
            response = await httpClient.PutAsync <GetCustomerResponse>(requestPath, bytes);

            Assert.That(response.Customer.Id, Is.EqualTo(5));

            Stream ms = bytes.InMemoryStream();

            response = await httpClient.PostAsync <GetCustomerResponse>(requestPath, ms);

            Assert.That(response.Customer.Id, Is.EqualTo(5));
        }
        public void Can_send_Deflate_client_request_HttpClient()
        {
            var client = new JsonHttpClient(Config.ListeningOn)
            {
                RequestCompressionType = CompressionTypes.Deflate,
            };
            var response = client.Post(new HelloZip {
                Name = "Deflate"
            });

            Assert.That(response.Result, Is.EqualTo("Hello, Deflate"));
        }
        public void Can_send_GZip_client_request_HttpClient()
        {
            var client = new JsonHttpClient(Constants.ServiceStackBaseHost)
            {
                RequestCompressionType = CompressionTypes.GZip,
            };
            var response = client.Post(new HelloZip {
                Name = "GZIP"
            });

            Assert.That(response.Result, Is.EqualTo("Hello, GZIP"));
        }
        public void Can_send_GZip_client_request_list_HttpClient()
        {
            var client = new JsonHttpClient(Config.ListeningOn)
            {
                RequestCompressionType = CompressionTypes.GZip,
            };
            var response = client.Post(new HelloZip
            {
                Name = "GZIP",
                Test = new List <string> {
                    "Test"
                }
            });

            Assert.That(response.Result, Is.EqualTo("Hello, GZIP (1)"));
        }
예제 #5
0
        private static BloggingContext CreateContext(string userName, string password)
        {
            var client = new JsonHttpClient(ServiceStackShared.BaseAddress)
            {
                HttpMessageHandler = new HttpClientHandler {
                    ServerCertificateCustomValidationCallback = (req, cert, chain, errors) => true
                },
            };

            client.Post(new Authenticate
            {
                provider   = CredentialsAuthProvider.Name,
                UserName   = userName,
                Password   = password,
                RememberMe = true,
            });

            var optionsBuilder = new DbContextOptionsBuilder()
                                 .UseInternalServiceProvider(ServiceProvider)
                                 .EnableSensitiveDataLogging()
                                 .UseInfoCarrierClient(new ServiceStackInfoCarrierClient(client));

            return(new BloggingContext(optionsBuilder.Options));
        }
예제 #6
0
        public async Task Can_post_raw_response_as_raw_JSON_HttpClient()
        {
            var httpClient = new JsonHttpClient(BaseUrl);
            var request = new GetCustomer { CustomerId = 5 };
            var response = httpClient.Post(request);
            Assert.That(response.Customer.Id, Is.EqualTo(5));

            var requestPath = request.ToPostUrl();

            string json = request.ToJson();
            response = await httpClient.PostAsync<GetCustomerResponse>(requestPath, json);
            Assert.That(response.Customer.Id, Is.EqualTo(5));

            byte[] bytes = json.ToUtf8Bytes();
            response = await httpClient.PutAsync<GetCustomerResponse>(requestPath, bytes);
            Assert.That(response.Customer.Id, Is.EqualTo(5));

            Stream ms = new MemoryStream(bytes);
            response = await httpClient.PostAsync<GetCustomerResponse>(requestPath, ms);
            Assert.That(response.Customer.Id, Is.EqualTo(5));
        }
예제 #7
0
        public async Task <APIResponses.AuthRegister> LoginAnonymous(string username)
        {
            var fingerprintResponse = await _http.Post <APIResponses.AuthFingerprint>(Endpoints.AuthFingerprint);

            var registerRequest = new APIRequests.AuthRegisterRequest {
                Fingerprint = fingerprintResponse.Fingerprint, Username = username
            };
            var registerResponse = await _http.Post <APIResponses.AuthRegister>(Endpoints.AuthRegister, registerRequest);

            return(registerResponse);
        }