In the current setup, the response stream is parsed by the JSON decoder, which throws an exception due to reading a non-json formatted error message.
The reported exception simply states that the first character on the first line was not valid json, which is true, but does not help diagnose the problem.
In many cases this is a human readable message, such as "over quota", "permission denied", etc.
This update adds a stream that keeps the first 2kb of the response in an internal buffer, which can then be printed in case the JSON parsing fails.
Most of the added code is just simple redirects for calling the base stream in the peeking stream.
For some reason, when using HttpWebRequest.GetRequestStreamAsync, the
Amazon Cloud Drive and Box backends would fail when attempting to upload
larger amounts of data (these are the only backends that use the
PostMultipartAsync method).
This fixes issue #3756.
These parameters weren't being used in the method body, or being passed in by any callers (it looks like a copy / paste error when a previous method was converted into this one)
These are replaced with a new optional parameter (method) which allows the caller to request a custom HTTP method to be used.