'Uploading pdf File Method XUnit Tests and Error is (Unsupported Media type)

This is Method :

[Fact]
    public async Task UploadPermitFileAsync_ShouldWork()
    {
        var stream = File.OpenRead(@"D:\Repos\administrationservice\AdministrationService.Tests\Test.pdf");
        var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
        {
            Headers = new HeaderDictionary(),   
            ContentType = "application/pdf"
        };
        await GovRequest<FormFile, string> (file, HttpMethod.Post, "TaskController/Upload");
    }

private async Task GovRequest<M, T>(M model, HttpMethod httpMethod, string apiUrl) { var data = JsonConvert.SerializeObject(model);

        var httpContent = new StringContent(data, Encoding.UTF8, "application/json");

        var request = new HttpRequestMessage(httpMethod, $"https://localhost:44365/{apiUrl}")
        {
            Content = httpContent
        };
        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _tokenApiModel.Result.AccessToken);

        var response = await _client.SendAsync(request);

        var responseBody = await response.Content.ReadAsStringAsync();

        var result = JsonConvert.DeserializeObject<SuccessRespondModel<T>>(responseBody);

        Assert.True(result.Success);
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source