Windows UWP c# HttpClient POST and progress
<p>So I need a progressbar on my application and I copied Microsoft's open source example (sorry not sorry), and it works amazing, except if you have to include POST data (or I'm just an idiot and can't figure it out.</p>

<p>Working code:</p>

<pre><code>const uint streamLength = 100000;
            HttpStreamContent streamContent = new HttpStreamContent(new SlowInputStream(streamLength));
IProgress&lt;HttpProgress&gt; progress = new Progress&lt;HttpProgress&gt;(ProgressHandler);
                response = await httpClient.PostAsync(new Uri(settings.url + "/script.php"), streamContent).AsTask(cts.Token, progress);
</code></pre>

<p>That gives me my progress and everything, now I need to add 4 post values, before I had them in a dictionary like so:</p>

<pre><code>var values = new Dictionary&lt;string, string&gt;
        {
            { "1", "1" },
            { "2", "2" },
            { "3", "3" },
            { "4", "4" }
        };
</code></pre>

<p>Then I encoded them</p>

<pre><code>HttpFormUrlEncodedContent formContent = new HttpFormUrlEncodedContent(values);
</code></pre>

<p>How would I get my formContent (or if you want to do it another way, that works too) into the streamContent, because it looks like without the streamContent, that the progress does not work.</p>

<p>Edit 1:</p>

<p>So, it works, now the progress does not work anymore. Here Is my progress function</p>

<pre><code>private void ProgressHandler(HttpProgress progress)
    {
        Debug.WriteLine("Stage: " + progress.Stage.ToString());
        Debug.WriteLine("Retires: " + progress.Retries.ToString(CultureInfo.InvariantCulture));
        Debug.WriteLine("Bytes Sent: " + progress.BytesSent.ToString(CultureInfo.InvariantCulture));
        Debug.WriteLine("Bytes Received: " + progress.BytesReceived.ToString(CultureInfo.InvariantCulture));

        ulong totalBytesToSend = 0;
        if (progress.TotalBytesToSend.HasValue)
        {
            totalBytesToSend = progress.TotalBytesToSend.Value;
            Debug.WriteLine("Total Bytes To Send: " + totalBytesToSend.ToString(CultureInfo.InvariantCulture));
        }
        else
        {
            Debug.WriteLine("Total Bytes To Send: " + "unknown");
        }

        ulong totalBytesToReceive = 0;
        if (progress.TotalBytesToReceive.HasValue)
        {
            totalBytesToReceive = progress.TotalBytesToReceive.Value;
            Debug.WriteLine("Total Bytes To Receive: " + totalBytesToReceive.ToString(CultureInfo.InvariantCulture));
        }
        else
        {
            Debug.WriteLine("Total Bytes To Receive: " + "unknown");
        }

        double requestProgress = 0;
        if (progress.Stage == HttpProgressStage.SendingContent &amp;&amp; totalBytesToSend &gt; 0)
        {
            requestProgress = progress.BytesSent * 50 / totalBytesToSend;
        }
        else if (progress.Stage == HttpProgressStage.ReceivingContent)
        {
            // Start with 50 percent, request content was already sent.
            requestProgress += 50;

            if (totalBytesToReceive &gt; 0)
            {
                requestProgress += progress.BytesReceived * 50 / totalBytesToReceive;
            }
        }
        else
        {
            return;
        }
        Debug.WriteLine("Progress: " + requestProgress);
        snap_progress.Value = requestProgress;
    }
</code></pre>

<p>And here is what it shows in debug:</p>

<pre><code>Stage: ReceivingContent
Retires: 0
Bytes Sent: 180
Bytes Received: 6757607
Total Bytes To Send: 180
Total Bytes To Receive: unknown
Progress: 50
</code></pre>

<p>It is at unknown the entire time even though I see Bytes Received increasing.</p>