[Help Needed] I need to know how to do HTTP POST requests specifically to Reddit :)

ATuringtest

Elite Member
Joined
Mar 8, 2019
Messages
1,625
Reaction score
2,846
I've been through most of the YouTube video on this subject but I'm still having problems how to format the headers to login then post/comment.
Any help much appreciated :)
 
The best way to know how Reddit or any other site works is running a packet sniffer like Wireshark or even a web debugging tool like Fiddler (easier to use).
 
Here's a thing that might get you on the right track, haven't tested it mind you:

1. Open devtools, go to network tab
2. Make the request you want to automate via the browser
3. Find the corresponding request entry in the devtools network tab (probably want to click "xhr" filter to narrow traffic down to what is relevant)
4. Right click and "copy as cURL"
5. Go into postman and import the curl request. Pretty sure you just have to paste it in a box.

There you go, postman should display all of the headers/auth/params necessary in a beginner friendly way in their UI. Good luck, lmk if it works lol
 
Brilliant responces but this should really be under coding or smth..
 
You need to find the CSRF token It is a temp token and post it in the body along with the email and password

Don't rely on the network tab in the browser as it is super confusing

Use a tool like BurpSuite

Btw CRSF token will be found in a hidden form on /login page Just parse the HTML and extract it each time you want to login
 
Using the api..

Login:
Code:
const authData = Buffer.from(`${clientId}:${clientSecret}`).toString(
    "base64"
  );
  const loginUrl = "https://www.reddit.com/api/v1/access_token";
  try {
    const response = await Request(loginUrl, {
      method: "POST",
      proxy,
      headers: {
        Authorization: `Basic ${authData}`,
        "Content-Type": "application/x-www-form-urlencoded",
      },
      body: {
        grant_type: "password",
        username: username,
        password: password,
      },
    });
const { access_token } = response.data;

Send message to user:
Code:
const sendMessageUrl = "https://oauth.reddit.com/api/compose";
  let response: any = "";
  try {
    response = await Request(sendMessageUrl, {
      method: "POST",
      proxy,
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "Content-Type": "application/x-www-form-urlencoded",
        "User-Agent":
          "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9",
      },
      body: {
        api_type: "json",
        subject: subject,
        text: message,
        to: recipient,
      },
    });


Request is an axios request function (plus it has some proxy management with it as well), but it does not matter what you use. You could use the native fetch function in node. The same thing could be done in any programming language btw.

For more functionality, have a look at their documentation here..
Code:
https://www.reddit.com/dev/api/
 
@BlurryBit @SeasonedCode I understand both these concepts, I think I may have misinterpreted something I read on another code forum. I was under the delusion that I could post to Reddit using headers without API authorisation. But obviously you cant lol. I was mixing up headless with headers.
I use PRAW for some stuff, but I find you cant comment or post with PRAW on a lot of subreddits.
So for now I'll look into headless solutions to post and comment.
 
@BlurryBit @SeasonedCode I understand both these concepts, I think I may have misinterpreted something I read on another code forum. I was under the delusion that I could post to Reddit using headers without API authorisation. But obviously you cant lol. I was mixing up headless with headers.
I use PRAW for some stuff, but I find you cant comment or post with PRAW on a lot of subreddits.
So for now I'll look into headless solutions to post and comment.
No, you can do anything without any API or Praw
when you post a request it is necessary to add the body headers Just have the user agent and some other info
 
Reddit uses http2, so you need to use http2 if you want to copy it perfectly. If you don't copy it perfectly, they can easily detect that you're a bot. You will also need to use wireshark to get the headers in the correct orders and also tls paramters.
 
Back
Top