static void UploadFile() { string dataBoundary = "--xyz"; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(serverUrl); webRequest.ContentType = "multipart/form-data; boundary=" + dataBoundary; webRequest.Method = "POST"; string datasourceStr = String.Format( "--{0}\r\n" + "Content-Disposition: form-data; name=\"datasource\"; name=\"files\"\r\n" + "Content-Type: application/octet-stream\r\n" + "\r\n", dataBoundary, "sample"); string feedtypeStr = String.Format( "--{0}\r\n" + "Content-Disposition: form-data; name=\"feedtype\"; name=\"files\"\r\n" + "Content-Type: application/octet-stream\r\n" + "\r\n", dataBoundary, "full"); string fileStr = String.Format( "--{0}\r\n" + "Content-Disposition: form-data; name=\"data\"; filename=\"C:\\content.txt\"\r\n" + "Content-Type: application/octet-stream\r\n" + "\r\n", dataBoundary, @"C:\content.txt"); // Get the total form post size string totalString = datasourceStr + feedtypeStr + fileStr; /* byte[] datasourceBytes = Encoding.Default.GetBytes(datasourceStr); byte[] feedtypeBytes = Encoding.Default.GetBytes(feedtypeStr); byte[] fileBytes = Encoding.Default.GetBytes(fileStr); int totalBytes = datasourceBytes.Length + feedtypeBytes.Length + fileStr.Length; */ byte[] totalBytes = Encoding.Default.GetBytes(totalString); webRequest.ContentLength = totalBytes.Length; // Send the data Stream webStream = webRequest.GetRequestStream(); /* webStream.Write(datasourceBytes, 0, datasourceBytes.Length); webStream.Write(feedtypeBytes, 0, feedtypeBytes.Length); webStream.Write(fileBytes, 0, fileStr.Length); */ webStream.Write(totalBytes, 0, totalBytes.Length); webStream.Close(); // Read the response HttpWebResponse res = (HttpWebResponse)webRequest.GetResponse(); StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.Default); string backstr = sr.ReadToEnd(); Console.Write(backstr); sr.Close(); res.Close(); }
HttpWebResponse res = (HttpWebResponse)webRequest.GetResponse();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)