VMware {code} Community
Go2Guy
Contributor
Contributor

HTTP Put fails with ESXi 4.1

I have c# code that I use to upload files to ESXi 4.0. The exact same code fails after upgrade to 4.1. I get this error: "This request requires buffering data to succeed."

Any suggestions? I've tried pre-authentication by connecting with the method = "HEAD" (as suggested here: ) but it just hangs.

url is the url to the ESXi datastore with file path and file name.

_cookie is the cookie I get from connecting to the ESXi web service before I do the upload.

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);

req.KeepAlive = false;

req.SendChunked = true;

req.Timeout = Timeout.Infinite;

req.AllowWriteStreamBuffering = false;

req.PreAuthenticate = true;

req.Method = "PUT";

req.Credentials = new NetworkCredential(_login, _password);

req.Headers.Add(HttpRequestHeader.Cookie, _cookie);

using (Stream reqStream = req.GetRequestStream())

{

// Open the local file

using (FileStream rdr = new FileStream(_filepath, FileMode.Open, FileAccess.Read, FileShare.Read))

{

// Allocate byte buffer to hold file contents

byte[] inData = new byte[http://Int16.MaxValue|http://Int16.MaxValue];

int bytesRead;

long totalBytesRead = 0;

FileInfo inputFileInfo = new FileInfo(_filepath);

long totalBytes = inputFileInfo.Length;

int lastPercent = 0;

while ((bytesRead = rdr.Read(inData, 0, inData.Length)) != 0)

{

reqStream.Write(inData, 0, bytesRead);

totalBytesRead += bytesRead;

}

Array.Resize(ref inData, 0);

}

}

req.GetResponse().Close();

0 Kudos
2 Replies
Go2Guy
Contributor
Contributor

Looking at it furthur shows an web exception: The request was aborted: The request was canceled.

0 Kudos
Go2Guy
Contributor
Contributor

Fiddler shows a 501.

0 Kudos