Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8011345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:59:22+00:00 2026-06-04T18:59:22+00:00

My problem is with the request headers. This is a little script I cooked

  • 0

My problem is with the request headers.

This is a little script I cooked up which doesn’t work:

require 'httparty'
require 'highline/import'

#Login.new.post lets us log in. Everything works up to the subreddits method.

class Login
  include HTTParty
  base_uri 'www.reddit.com'
#So far, so good.

  def post(username, password)
    options = {:body => {:user => username, :passwd => password, :api_type => 'json'}}
    self.class.post("/api/login/#{username}", options)
  end

#I think this part is right, in and of itself. The problem is in how the headers
#are composed (which is why I keep bonking my head on the wall.)
  def subreddits(headers)
    self.class.get("/reddits/mine", headers)
  end

  def cli_user_login(user, password)
    a = Login.new.post(user, password);
    puts a;
    #We logged in and got some JSON with an empty errors array and, nestled deep, a cookie.
    reddit_session = a["json"]["data"]["cookie"]
    #Just putting the cookie in a variable. Print it to make sure it's there:
    puts reddit_session
    #reddit_session displays, no problem. We HAVE the cookie.
  b = Login.new.subreddits("headers" => {"reddit_session" => reddit_session})
  puts b
  #Then suddenly it spits out a mountain of html....... but not the subreddits! :(
  end

end


##The following is just for testing, because I'm whimsical or stupid or something
class IWouldLikeToPlayAGame
  def initialize
    puts "PLEASE ETNER YOUR REDDIT CRITERIALS"
    a = gets.chomp.strip
    b = ask("PLEASE BE ENTERING YOUR RREDDIT password"){ |q| q.echo = false }

    Login.new.cli_user_login(a, b)
  end
end

IWouldLikeToPlayAGame.new

I think my error is around line 30. My headers hash looks like this:

{"headers" => {"reddit_session" => cookie}}

GET reddit.com/reddits/mine.xml with that header and I should have the subreddit listing, right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:59:23+00:00Added an answer on June 4, 2026 at 6:59 pm

    First you need to specify format extension for data that you want to get, xml or json:

    /reddits/mine.extension
    

    Second you need to send reddit_session in cookies hash, not headers:

    :cookies => {'reddit_session' => reddit_session}
    

    Semicolons in ruby are optional, better to omit them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem sending POST request with VB6. The code below works properly
My problem is that Backbone is trying to do an HTTP request on a
I am having a problem with a network request that should timeout, but the
I've a problem with a slow post request in a RoR app. the project
I have the next problem: I need to process only 1 request at a
I have a problem when trying to send a POST request. The sending method
I'm having the following problem when using GWT and request factory. I am working
I've a problem. I try to send a JSON request to a web server
I am designing a workflow for an absence request at my company. The problem
I'm facing a problem here, with HttpListener. When a request of the form http://user:password@example.com/

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.