Preserve Binary File Bytes When Uploading Through a Proxy
Preserve file bytes and byte lengths when uploading through a proxy instead of decoding the artifact as text and rebuilding it with ASCII.
A binary file should reach the HTTP client as bytes. Reading it with a text reader and re-encoding the resulting string as ASCII can replace values before the proxy receives anything. A small text sample working does not make that path safe for an image, archive or document.
In an existing .NET upload path, replace that conversion with a binary body source:
using var file = File.OpenRead(path);
using var content = new StreamContent(file);
Pass the content through the application's configured HTTP upload; the fragment establishes the body source, while the existing client still owns the method, destination, proxy and lifetime handling.
Remove any Content-Length calculated from the old string's character count. The field measures octets. Let the HTTP library construct framing from the body representation instead of pairing a character count with a differently encoded buffer.
For an intentional text upload, choose the encoding explicitly and derive any required length from the bytes sent. That text-format decision should not be applied to arbitrary files.
Compare the transferred artifact with a trusted expected value. HTTP success confirms that an upload operation completed at that layer; it cannot show that a prior text conversion preserved the original bytes.