Fixe l'envoi du fichier

broken/ef
Paul Schneider 3 years ago
parent e0a3ec0bd5
commit efb004ee08
1 changed files with 6 additions and 8 deletions

@ -24,11 +24,10 @@ namespace nuget_cli
// "X-NuGet-ApiKey
string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
byte[] boudaryByte = Encoding.ASCII.GetBytes(boundary);
byte[] trailer = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
string fileheader = string.Format(fileheaderTemplate, "file", fi.Name, "application/octet-stream");
byte[] fileheaderbytes = Encoding.ASCII.GetBytes(fileheader);
var boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
var endBoundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--");
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
httpWebRequest.Method = "PUT";
@ -36,7 +35,8 @@ namespace nuget_cli
httpWebRequest.AllowAutoRedirect = false;
httpWebRequest.Headers.Add("X-NuGet-Client-Version", Constants.ClientVersion);
httpWebRequest.Headers.Add("X-NuGet-ApiKey", apikey);
httpWebRequest.ContentLength = boudaryByte.Length + fileheaderbytes.Length + fi.Length + trailer.Length;
httpWebRequest.ContentLength = boundarybytes.Length +
fileheaderbytes.Length + fi.Length + endBoundaryBytes.Length;
httpWebRequest.BeginGetRequestStream((result) =>
@ -47,10 +47,8 @@ namespace nuget_cli
using (Stream requestStream = request.EndGetRequestStream(result))
{
WriteToStream(requestStream, boudaryByte, boudaryByte.Length);
WriteToStream(requestStream, boundarybytes, boundarybytes.Length);
WriteToStream(requestStream, fileheaderbytes, fileheaderbytes.Length);
// WriteToStream(s, string.Format(fileheaderlentemplate, fi.Length));
/// Write the file data to the stream.
using (var fss = fi.OpenRead())
{
byte[] buffer = new byte[TXLEN];
@ -61,7 +59,7 @@ namespace nuget_cli
form_bytes_read = fss.Read(buffer, 0, TXLEN);
}
}
requestStream.Write(trailer, 0, trailer.Length);
requestStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
requestStream.Close();
}

Loading…