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

  • SEARCH
  • Home
  • 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 3967104
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:40:50+00:00 2026-05-20T03:40:50+00:00

I am using Ruby on Rails 3 and I would like to set header

  • 0

I am using Ruby on Rails 3 and I would like to set header and params values for a HTTP GET request of a client server. Then, on the other side, I would like to read those on the service server.

What I do in the client is:

host = "http://<site_name>.com"
path = "/users/1.json"
query_params = ["username=test_username", "password=test_psw"].join("&")

uri = URI.parse("#{host}#{path}?#{query_params}")

http = Net::HTTP.new(uri.host, uri.port)

http.start do
  @response_test = JSON(http.get("#{host}#{path}").body)["user"]
end

What I do in the service is:

...
respond_to do |format|
  format.json {
    render :json => @user.to_json
    if ( params["username"] == "test_username" && password == test_psw )
      render :json => @user.to_json
    else
      render :text => "Bad request"
    end
  }
end

All above code doesn’t work correctly: making the HTTP GET request I get always a 706: unexpected token at 'Bad request'.

(1) How set correctly the header in the client? In the example above, are params correctly set?

(2) How to read properly header and params values in the server?

  • 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-05-20T03:40:51+00:00Added an answer on May 20, 2026 at 3:40 am

    Are you getting the “706: unexpected token at ‘Bad request'” error on the client side after attempting to parse the response? If so I would guess this is because your client appears to be expecting a JSON response, and you’re sending the unquoted raw text “Bad request”, which does not parse as valid JSON. Try render :json => "Bad request".to_json

    Any parameters passed in a GET querystring or form POST will be in the params hash.

    In answer to your questions:

    1) You can see your params by putting puts "params: #{params.inspect}" inside your controller action.

    2) Headers are available in the request.headers hash: http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-headers

    Here’s how to set headers in a Net::HTTP request:

    url = URI.parse("http://www.whatismyip.com/automation/n09230945.asp")
    
    req = Net::HTTP::Get.new(url.path)
    req.add_field("X-Forwarded-For", "0.0.0.0")
    
    res = Net::HTTP.new(url.host, url.port).start do |http|
      http.request(req)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create something like this using ruby on rails. Im not
I am using Ruby on Rails 3 and I am trying to set values
I am using Ruby on Rails 3 and I would like to initialize my
I am using Ruby on Rails 3 and I would like to know some
I am running Ruby on Rails 3 and I would like to set up
I am running Ruby on Rails 3 and I would like to set up
I am running Ruby on Rails 3 and I would like to set up
I would like to use Kdevelep as a Ruby on Rails IDE as I'm
I am running Ruby on Rails 3 and Prototype and I would like to
I am using Ruby on Rails. I want to create a filter field on

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.