I'm trying to create a program to log into reddit and do some actions for me, reddit requires:
CSRF, OTP, PASS, DEST, USER
when sending the post request and I am definitely filling all of these with the right data but for some reason I cannot get a response from reddit, the program crashes
`
using System;
using System.Net.Http;
using System.Collections.Generic;
// Set up the HTTP client
static string getBetween(string strSource, string strStart, string strEnd)
{
if (strSource.Contains(strStart) && strSource.Contains(strEnd))
{
int Start, End;
Start = strSource.IndexOf(strStart, 0) + strStart.Length;
End = strSource.IndexOf(strEnd, Start);
return strSource.Substring(Start, End - Start);
}
return "";
}
var client = new HttpClient();
client.DefaultRequestHeaders.Add("UserAgent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0");
client.DefaultRequestHeaders.Add("Pragma", "no-cache");
client.DefaultRequestHeaders.Add("Accept", "*/*");
client.DefaultRequestHeaders.Add("Referer", "https://www.google.com");
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded");
//client.DefaultRequestHeaders.Add("Content-Type", "application/x-www-form-urlencoded");
client.BaseAddress = new Uri("https://www.reddit.com/");
string csrf = "FAIL";
using (var response = client.GetAsync("https://www.reddit.com/login").Result)
{
if (response.IsSuccessStatusCode)
{
csrf = getBetween(response.Content.ReadAsStringAsync().Result, "csrf_token\" value=\"", "\"");
}
}
Console.WriteLine(csrf);
// Set up the login form data
var formData = new Dictionary<string, string>
{
{ "csrf_token", csrf},
{ "otp", "" },
{ "password", "XXXX" },
{ "dest", "https://reddit.com/" },
{ "username", "XXXX" }
};
// Post the login form
var response4 = await client.PostAsync("https://www.reddit.com/login/", new FormUrlEncodedContent(formData));
// Check the response status code
//if (response.IsSuccessStatusCode)
//{
// Console.WriteLine("Login successful!");
//}
//else
//{
// Console.WriteLine("Login failed!");
//}
`
and it seems reddit just doesn't give a response, my program immediately crashes. anyone could give me some insight maybe? thank you
I tried changing it up and playing a bit with the headers to no avail