Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string pastebin_login_url = "http://pastebin.com/api/api_login.php";
- string pastebin_post_url = "http://pastebin.com/api/api_post.php";
- string pastebin_dev_key = "???????????????????????????";
- string _pastebinUserKey = null;
- void SendViaPasteBin() {
- string body = GetText(txtMain);
- string subject = txtSubject.Text.Trim();
- if(string.IsNullOrEmpty(subject)) {
- subject = "Note " + DateTime.Now.ToLongDateString() + ":" + DateTime.Now.ToShortTimeString();
- }
- string api_paste_format = "csharp";
- string userk = LogInToPasteBin();
- NameValueCollection values = new NameValueCollection();
- values.Add("api_dev_key",pastebin_dev_key);
- values.Add("api_option","paste");
- values.Add("api_paste_code",body);
- values.Add("api_paste_private","0");
- values.Add("api_paste_name",subject);
- values.Add("api_paste_expire_date","N");
- values.Add("api_paste_format",api_paste_format);
- values.Add("api_user_key",userk);
- using(WebClient wc = new WebClient()) {
- byte[] respBytes = wc.UploadValues(pastebin_post_url,values);
- string respString = Encoding.UTF8.GetString(respBytes);
- Uri valid = null;
- if(Uri.TryCreate(respString,UriKind.Absolute,out valid)) {
- MessageBox.Show("Success: " + valid.ToString());
- }
- else {
- MessageBox.Show("Error:" + respString);
- }
- }
- }
- string LogInToPasteBin() {
- if(_pastebinUserKey != null)
- return _pastebinUserKey;
- string userName = "?????????";
- string pwd = "?????????";
- NameValueCollection values = new NameValueCollection();
- values.Add("api_dev_key",pastebin_dev_key);
- values.Add("api_user_name",userName);
- values.Add("api_user_password",pwd);
- using(WebClient wc = new WebClient()) {
- byte[] respBytes = wc.UploadValues(pastebin_login_url,values);
- string resp = Encoding.UTF8.GetString(respBytes);
- if(resp.Contains("Bad API request")) {
- MessageBox.Show("Error:" + resp);
- return null;
- }
- _pastebinUserKey = resp;
- }
- return _pastebinUserKey;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement