Repository: PowerShell/PowerShell
File: src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs (C#)

Code before:
            {
                // Just in case there are any edge cases we missed, we don't break workflows with an exception
                WriteVerbose($"Failed to Write WebRequest Verbose Info: {ex} {ex.StackTrace}");
            }
        }

        private void GetWebRequestDebugInfo(HttpRequestMessage request)
        {
            try
            {
                // Typical basic example:
                // WebRequest Detail
                // ---QUERY
                // test = 5
                // --- HEADERS
                // User - Agent: Mozilla / 5.0, (Linux;Ubuntu 24.04.2 LTS;en - US), PowerShell / 7.6.0
                StringBuilder debugBuilder = new("WebRequest Detail" + Environment.NewLine, 512);

                if (!string.IsNullOrEmpty(request.RequestUri?.Query))
                {
                    debugBuilder.Append(DebugHeaderPrefix).AppendLine("QUERY");
                    string[] queryParams = request.RequestUri.Query.TrimStart('?').Split('&');
                    foreach (string param in queryParams)
                    {
                        debugBuilder.AppendLine(param);
                    }
                }

                debugBuilder.Append(DebugHeaderPrefix).AppendLine("HEADERS");

                foreach (var headerSet in new HttpHeaders?[] { request.Headers, request.Content?.Headers })
                {
                    if (headerSet is null)
                    {
                        continue;
                    }

                    foreach (var header in headerSet)
                    {
                        debugBuilder
                        .Append($"{header.Key}: ")
                        .AppendJoin(", ", header.Value)
                        .AppendLine();
                    }
                }

                if (request.Content is not null)
                {
                    debugBuilder
                    .AppendLine(DebugHeaderPrefix + "BODY")
                    .AppendLine(request.Content switch

Review comment (bug):
```suggestion
                    debugBuilder.AppendJoin(Environment.NewLine, queryParams);
```

Code after:
                WriteVerbose(verboseBuilder.ToString().Trim());
            }
            catch (Exception ex)
            {
                // Just in case there are any edge cases we missed, we don't break workflows with an exception
                WriteVerbose($"Failed to Write WebRequest Verbose Info: {ex} {ex.StackTrace}");
            }
        }

        private void WriteWebRequestDebugInfo(HttpRequestMessage request)
        {
            try
            {
                // Typical basic example:
                // WebRequest Detail
                // ---QUERY
                // test = 5
                // --- HEADERS
                // User - Agent: Mozilla / 5.0, (Linux;Ubuntu 24.04.2 LTS;en - US), PowerShell / 7.6.0
                StringBuilder debugBuilder = new("WebRequest Detail" + Environment.NewLine, 512);

                if (!string.IsNullOrEmpty(request.RequestUri?.Query))
                {
                    debugBuilder.Append(DebugHeaderPrefix).AppendLine("QUERY");
                    string[] queryParams = request.RequestUri.Query.TrimStart('?').Split('&');
                    debugBuilder
                        .AppendJoin(Environment.NewLine, queryParams)
                        .AppendLine()
                        .AppendLine();
                }

                debugBuilder.Append(DebugHeaderPrefix).AppendLine("HEADERS");

                foreach (var headerSet in new HttpHeaders?[] { request.Headers, request.Content?.Headers })
                {
                    if (headerSet is null)
                    {
                        continue;
                    }

                    debugBuilder.AppendLine(headerSet.ToString());
                }

                if (request.Content is not null)
                {
                    debugBuilder
                    .Append(DebugHeaderPrefix).AppendLine("BODY")
                    .AppendLine(request.Content switch
                    {
                        StringContent stringContent => stringContent
                            .ReadAsStringAsync(_cancelToken.Token)