I'm trying to make a program that will create an account on Reddit using an HttpWebRequest
. I ONLY want it to do that. (I don't care about it storing a cookie or anything else.) I just want it to be a simple program where you type a username into Username_TextBox.Text
and a password into Password_TextBox.Text
and then click the CreateAccount_Button
and voilà, new account created!
I followed a tutorial on YouTube that poorly explained how everything about a HttpWebRequest
worked.
Currently, the program will create a Reddit account as long as the username hasn't been taken already. I just don't want any excess code that is useless. I want any extra code removed that isn't contributing to my goal mentioned above.
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using System;
namespace RedditAccountCreate
{
public partial class RedditAccountCreate : Form
{
public RedditAccountCreate()
{
InitializeComponent();
}
CookieContainer CreateAccountCookie;
private void CreateAccount_Button_Click(object sender, EventArgs e)
{
string POSTData = "op=reg&dest=https%3A%2F%2Fwww.reddit.com%2F&user=" + Username_TextBox.Text + "&passwd=" + Password_TextBox.Text + "&passwd2=" + Password_TextBox.Text + "&email=&api_type=json";
CookieContainer TemporaryCookie = new CookieContainer();
UTF8Encoding Encoding = new UTF8Encoding();
byte[] ByteData = Encoding.GetBytes(POSTData);
HttpWebRequest POSTRequest = (HttpWebRequest)WebRequest.Create("https://www.reddit.com/api/register/" + Username_TextBox.Text);
POSTRequest.Method = "POST";
POSTRequest.KeepAlive = true;
POSTRequest.CookieContainer = TemporaryCookie;
POSTRequest.ContentType = "application/x-www-form-urlencoded";
POSTRequest.Referer = "http://www.reddit.com/";
POSTRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
POSTRequest.ContentLength = ByteData.Length;
Stream POSTRequestStream = POSTRequest.GetRequestStream();
POSTRequestStream.Write(ByteData, 0, ByteData.Length);
POSTRequestStream.Close();
HttpWebResponse POSTResponse = default(HttpWebResponse);
POSTResponse = (HttpWebResponse)POSTRequest.GetResponse();
TemporaryCookie.Add(POSTResponse.Cookies);
CreateAccountCookie = TemporaryCookie;
StreamReader POSTRequestReader = new StreamReader(POSTResponse.GetResponseStream());
string POSTRequestCode = POSTRequestReader.ReadToEnd();
}
}
}
Here's the link to the YouTube tutorial that I followed, in case anyone wants it.