Uploading files using HttpWebRequest and PUT takes too long

T

tregewitz

I am uploading a zip file using an HttpWebRequest and a PUT operation
to Sharepoint (2003) from a Windows Form application. When I upload
the same file using the Sharepoint Portal Web UI itself, the file
uploads in 1/3 the time. If I copy the file over the network using
Windows Explorer, it also copies in about 1/3 of the time.

I don't understand why it is taking so much longer transferring it in
this way.

I've tried several variations of this code, but there's no difference:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = userNetworkCredentials;
request.Method = "PUT";
request.ContentType = "application/octet-stream";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data,0,data.Length);
stream.Close();
response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
temp = reader.ReadToEnd();
reader.Close();

Anybody know a way to improve the performance?
 
T

tregewitz

I've now isolated the problem though I don't have a solution yet. The
file actually is being sent 3 times. But the first 2 times it is
being sent without the proper credentials. The server responds with
401-Unathorized. Apparently the HttpWebRequest has to go through 3
iterations of negotating security credentials before it gets it
right. Even when the Preauthenticate property is set to true, it
doesn't matter for the first request.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top