Last active
October 20, 2015 05:40
-
-
Save cmpunches/c7860fe5e8e827701328 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void DoUpload() | |
{ | |
IgnoreBadCertificates(); | |
using (WebClient Client = new WebClient()) | |
{ | |
INI Settings = new INI("settings.ini"); | |
// this method in powershell: | |
// $WR = Invoke - WebRequest $uri - Method $HTTP_COMMAND - ContentType "application/octet-stream" - InFile $localpath - headers $headers - EA Stop - EV e | |
foreach (string header in WebRequestCreateCustomHeaders()) | |
{ | |
Client.Headers.Add(header); | |
} | |
Client.Headers.Add("Content-Type", "application/octet-stream"); | |
try | |
{ | |
byte[] rawResponse = Client.UploadFile(this.URI, this.HTTP_Command, this.LocalFilePath); | |
string response = System.Text.Encoding.ASCII.GetString(rawResponse); | |
Notifications.Notify(response, Settings.Read("path", "logging"), true, ConsoleColor.Red); | |
WebResponse response = (WebResponse)(typeof(WebClient).GetField("m_WebResponse", System.Reflection.BindingFlags.NonPublic).GetValue(Client)); | |
HttpStatusCode statusCode = ((HttpWebResponse)response).StatusCode; | |
} | |
catch (Exception e) | |
{ | |
Notifications.Notify(this.ToString(), Settings.Read("path", "logging"), true, ConsoleColor.Red); | |
Notifications.Notify(e.Message, Settings.Read("path", "logging"), true, ConsoleColor.Red); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment