public async Task SendAsync_SendRequestUsingMethodToEchoServerWithContent_Success( string method, Uri serverUri) { using (HttpClient client = CreateHttpClient()) { var request = new HttpRequestMessage( new HttpMethod(method), serverUri) { Version = UseVersion }; request.Content = new StringContent(ExpectedContent); using (HttpResponseMessage response = await client.SendAsync(TestAsync, request)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); TestHelper.VerifyRequestMethod(response, method); string responseContent = await response.Content.ReadAsStringAsync(); _output.WriteLine(responseContent); Assert.Contains($"\"Content-Length\": \"{request.Content.Headers.ContentLength.Value}\"", responseContent); TestHelper.VerifyResponseBody( responseContent, response.Content.Headers.ContentMD5, false, ExpectedContent); } } }
public async Task SendAsync_SendRequestUsingNoBodyMethodToEchoServerWithContent_NoBodySent( string method, Uri serverUri) { using (HttpClient client = CreateHttpClient()) { var request = new HttpRequestMessage( new HttpMethod(method), serverUri) { Content = new StringContent(ExpectedContent), Version = UseVersion }; using (HttpResponseMessage response = await client.SendAsync(TestAsync, request)) { if (method == "TRACE") { // .NET Framework also allows the HttpWebRequest and HttpClient APIs to send a request using 'TRACE' // verb and a request body. The usual response from a server is "400 Bad Request". // See here for more info: https://github.com/dotnet/runtime/issues/17475 Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } else { Assert.Equal(HttpStatusCode.OK, response.StatusCode); TestHelper.VerifyRequestMethod(response, method); string responseContent = await response.Content.ReadAsStringAsync(); Assert.DoesNotContain(ExpectedContent, responseContent); } } } }
public async Task SendAsync_SendRequestUsingMethodToEchoServerWithContent_Success( string method, bool secureServer) { using (var client = new HttpClient()) { var request = new HttpRequestMessage( new HttpMethod(method), secureServer ? HttpTestServers.SecureRemoteEchoServer : HttpTestServers.RemoteEchoServer); request.Content = new StringContent(ExpectedContent); using (HttpResponseMessage response = await client.SendAsync(request)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); TestHelper.VerifyRequestMethod(response, method); string responseContent = await response.Content.ReadAsStringAsync(); _output.WriteLine(responseContent); TestHelper.VerifyResponseBody( responseContent, response.Content.Headers.ContentMD5, false, ExpectedContent); } } }
public async Task SendAsync_SendRequestUsingMethodToEchoServerWithNoContent_MethodCorrectlySent( string method, Uri serverUri) { if (method == "TRACE" && PlatformDetection.IsBrowser) { // [ActiveIssue("https://github.com/dotnet/runtime/issues/53592", TestPlatforms.Browser)] return; } using (HttpClient client = CreateHttpClient()) { var request = new HttpRequestMessage( new HttpMethod(method), serverUri) { Version = UseVersion }; using (HttpResponseMessage response = await client.SendAsync(TestAsync, request)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); TestHelper.VerifyRequestMethod(response, method); } } }
public async Task SendAsync_SendRequestUsingMethodToEchoServerWithNoContent_MethodCorrectlySent( string method, bool secureServer) { using (var client = new HttpClient()) { var request = new HttpRequestMessage( new HttpMethod(method), secureServer ? HttpTestServers.SecureRemoteEchoServer : HttpTestServers.RemoteEchoServer); using (HttpResponseMessage response = await client.SendAsync(request)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); TestHelper.VerifyRequestMethod(response, method); } } }
public async Task SendAsync_SendRequestUsingMethodToEchoServerWithNoContent_MethodCorrectlySent( string method, Uri serverUri) { using (HttpClient client = CreateHttpClient()) { var request = new HttpRequestMessage( new HttpMethod(method), serverUri) { Version = UseVersion }; using (HttpResponseMessage response = await client.SendAsync(TestAsync, request)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); TestHelper.VerifyRequestMethod(response, method); } } }
public async Task SendAsync_SendRequestUsingMethodToEchoServerWithContent_Success( string method, Uri serverUri) { if (method == "GET" && PlatformDetection.IsBrowser) { // [ActiveIssue("https://github.com/dotnet/runtime/issues/53591", TestPlatforms.Browser)] return; } using (HttpClient client = CreateHttpClient()) { var request = new HttpRequestMessage( new HttpMethod(method), serverUri) { Version = UseVersion }; request.Content = new StringContent(ExpectedContent); using (HttpResponseMessage response = await client.SendAsync(TestAsync, request)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); TestHelper.VerifyRequestMethod(response, method); string responseContent = await response.Content.ReadAsStringAsync(); _output.WriteLine(responseContent); Assert.Contains($"\"Content-Length\": \"{request.Content.Headers.ContentLength.Value}\"", responseContent); TestHelper.VerifyResponseBody( responseContent, response.Content.Headers.ContentMD5, false, ExpectedContent); } } }