using (var stream = uploadFile.OpenRead())
{
var webRes = webReq.UploadFile(stream, uploadFile.Name, MimeTypes.GetMimeType(uploadFile.Name));
}
But the VS2019 compiler throws an error saying that I “Cannot assign void to an implicitly-typed variable”, which seems correct, as the UploadFile method indeed do return void…?
Furthermore, I cant seem to get any response afterwards. The HttpWebRequest’s HaveResponse property is false - even tough Fiddler show the following result:
{“errors”:[{“type”:“E”,“text”:“java.nio.file.FileSystemException: \\SRVTTIAFIL01\Applications\ttia5201\TSFA\SRVTTIAFIL01\Applications\ttia5201\TSFA\archive: The user name or password is incorrect.\r\n”,“timestamp”:“2020-02-15T10:42:45.472”}]}
Yep it doesn’t return anything so the example shouldn’t have a response which I’ve just updated. FYI The “Edit on GitHub” link in the top right of every change with let you send a quick PR update to fix any doc errors.
The point is that UploadFile doesn’t return anything OR throw any exception, even though the remote server returns an error and code 500. So how do I get the response, Fiddler shows is there?
This is my code (the service acts as a proxy for a backend webservice).
I’d take KeepAlive off, as you’re not attempting to reuse a persistent connection.
UploadFile does not swallow the Exception so it should throw, maybe your Proxy is muting it somehow, either way there’s nothing more the library can do, the HttpWebRequest docs says it throws a WebException when errors occur while accessing a resource, I can’t say why it’s not throwing for you, I’ve never heard of an issue where it was not throwing for HTTP Error responses before.