I get "BAD Request" error when I try to PUT a file to artifactory - I was to read folder info and other GET operations - I am wondering if I am missing something in headers - if someone can provide suggestions, it will be extremely valuable... see my code below..
string url = "https://myserver.com/artifactory/api/storage/myreponame "; long length = 0; string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x"); HttpWebRequest httpWebRequest2 = (HttpWebRequest)WebRequest.Create(url); httpWebRequest2.ContentType = "text/plain"; httpWebRequest2.Method = "PUT"; httpWebRequest2.KeepAlive = true; httpWebRequest2.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("username:password")); //adding headers- what am i missing here?? httpWebRequest2.Headers["X-Checksum-Md5"] = "d41d8cd98f00b204e9800998ecf8427e"; httpWebRequest2.Headers["X-Checksum-Sha1"] = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; httpWebRequest2.Credentials = new NetworkCredential("unm", "password"); Stream memStream = new System.IO.MemoryStream(); byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); memStream.Write(boundarybytes, 0, boundarybytes.Length); length += boundarybytes.Length; string headerTemplate = "Content-Disposition: form-data; name=\"{0}\";filename=\"{1}\"\r\n Content-Type: application/octet-stream\r\n\r\n"; string file = @"c:\temp\temp.txt" ; string header = string.Format(headerTemplate, "file0", file); byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header); memStream.Write(headerbytes, 0, headerbytes.Length); length += headerbytes.Length; FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read); byte[] buffer = new byte[1024]; int bytesRead = 0; while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0) { memStream.Write(buffer, 0, bytesRead); length += bytesRead; } memStream.Write(boundarybytes, 0, boundarybytes.Length); length += boundarybytes.Length; fileStream.Close(); } httpWebRequest2.ContentLength = memStream.Length; Stream requestStream = httpWebRequest2.GetRequestStream(); memStream.Position = 0; byte[] tempBuffer = new byte[memStream.Length]; memStream.Read(tempBuffer, 0, tempBuffer.Length); memStream.Close(); requestStream.Write(tempBuffer, 0, tempBuffer.Length); requestStream.Close(); WebResponse webResponse2 = httpWebRequest2.GetResponse(); Stream stream2 = webResponse2.GetResponseStream(); StreamReader reader2 = new StreamReader(stream2); Console.Write(reader2.ReadToEnd()); webResponse2.Close(); httpWebRequest2 = null; webResponse2 = null; -- View this message in context: http://forums.jfrog.org/Deploy-Artifact-using-REST-API-C-tp7579939.html Sent from the Artifactory - Users mailing list archive at Nabble.com. ------------------------------------------------------------------------------ _______________________________________________ Artifactory-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/artifactory-users
