Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string Create()
- {
- string authInfo = "username" + ":" + "password";
- string root = AppDomain.CurrentDomain.BaseDirectory;
- string file = root + "Folder\work.txt";
- FileInfo fi = new FileInfo(file);
- int fileLength = (int)fi.Length;
- FileStream rdr = new FileStream(file, FileMode.Open);
- HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
- httpWebRequest.Method = "POST";
- httpWebRequest.ContentType = "application/x-www-form-urlencoded";
- httpWebRequest.Accept = "application/xml";
- authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
- httpWebRequest.Headers["Authorization"] = "Basic " + authInfo;
- byte[] requestBytes = new byte[fileLength];
- int bytesRead = 0;
- httpWebRequest.ContentLength = requestBytes.Length;
- using (Stream requestStream = httpWebRequest.GetRequestStream())
- {
- while ((bytesRead = rdr.Read(requestBytes, 0, requestBytes.Length)) != 0)
- {
- requestStream.Write(requestBytes, 0, bytesRead);
- requestStream.Close();
- }
- }
- //READ RESPONSE FROM STREAM
- string responseData;
- using (StreamReader responseStream = new StreamReader(httpWebRequest.GetResponse().GetResponseStream()))
- {
- responseData = responseStream.ReadToEnd();
- responseStream.Close();
- }
- return responseData;
- }
Add Comment
Please, Sign In to add comment