Skip to content

BreakShoot/CSharpHastebinAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

CSharpHastebinAPI

A small method for uploading text to hastebin.com

Code

using System;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;

string UploadHaste(string text)
{
    string returnedjson = null;

    using (WebClient client = new WebClient())
        returnedjson = client.UploadString("https://hastebin.com/documents", text);

    if (returnedjson == null)
        throw new Exception("Failed to get response from https://hastebin.com/documents");

    using (XmlDictionaryReader jsonReader =
        JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(returnedjson),
            new System.Xml.XmlDictionaryReaderQuotas()))
    {
        return $"hastebin.com/{XElement.Load(jsonReader).XPathSelectElement("//key")?.Value}";
    }
}

Example Calling

void SomeMethod() {
  Console.WriteLine(UploadHaste("some example test"));
  //will print a hastebin link containing your text!
}

About

A small method for uploading text to hastebin.com

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published