I’m switching from regular files to zip files doing an upload, and was told I’d need to use a header in this format – Content-Type: application/zip.
So, I can get my file to upload properly via curl with the following:
curl --verbose --header "Content-Type: application/zip" --data-binary @C:\Junk\test.zip "http://client.xyz.com/submit?username=test@test.com&password=testpassword&job=test"
However, when I write a simple powershell script to do the same thing, I run into problems – the data isn’t loaded. I don’t know how to get a good error message returned, so I don’t know the details, but bottom line the data isn’t getting in.
$FullFileName = "C:\Junk\test.zip"
$wc = new-object System.Net.WebClient -Verbose
$wc.Headers.Add("Content-Type: application/zip")
$URL = "http://client.xyz.com/submit?username=test@test.com&password=testpassword&job=test"
$wc.UploadFile( $URL, $FullFileName )
# $wc.UploadData( $URL, $FullFileName )
I’ve tried using UploadData instead of UploadFile, but that doesn’t appear to work either.
Thanks,
Sylvia
I don’t necessarily have a solution but I think the issue is that you are trying to upload a binary file using the WebClient object. You most likely will need the UploadData method but I think you are going to have to run the zip file into an array of bytes to upload. That I’m not sure of off the top of my head.
If you haven’t, be sure to look at the MSDS docs for this class and methods: http://msdn.microsoft.com/en-us/library/system.net.webclient_methods.aspx