Skip to content

Instantly share code, notes, and snippets.

@cmpunches
Last active October 20, 2015 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmpunches/c7860fe5e8e827701328 to your computer and use it in GitHub Desktop.
Save cmpunches/c7860fe5e8e827701328 to your computer and use it in GitHub Desktop.
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