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 6101643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:31:24+00:00 2026-05-23T13:31:24+00:00

I’m very new to ruby and trying some basic stuff. When I send HTTP

  • 0

I’m very new to ruby and trying some basic stuff. When I send HTTP request to the server using:

curl -v -H "Content-Type: application/json" -X GET -d "{"myrequest":"myTest","reqid":"44","data":{"name":"test"}}" localhost:8099

My server sees JSON data as “{myrequest:myTest,reqid:44,data:{name:test}}”

But when I send the request using the following ruby code:

require 'net/http'

@host = 'localhost'
@port = '8099'

@path = "/posts"

@body = ActiveSupport::JSON.encode({
    :bbrequest => "BBTest", 
    :reqid => "44", 
    :data => 
    {
        :name => "test"
    }
})

request = Net::HTTP::Post.new(@path, initheader = {'Content-Type' =>'application/json'})
request.body = @body
response = Net::HTTP.new(@host, @port).start {|http| http.request(request) }
puts "Response #{response.code} #{response.message}: #{response.body}"

It sees it as “{\”bbrequest\”:\”BBTest\”,\”reqid\”:\”44\”,\”data\”:{\”name\”:\” test\”}}” and server is unable to parse it. Perhaps there are some extra options I need to set to send request from Ruby to exclude those extra characters?

Can you please help. Thanks in advance.

  • 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-23T13:31:24+00:00Added an answer on May 23, 2026 at 1:31 pm

    What you are doing on the shell produces invalid JSON. Your server should not accept it.

      $echo "{"myrequest":"myTest","reqid":"44","data":{"name":"test"}}"
          {myrequest:myTest,reqid:44,data:{name:test}}
    

    This is JSON with unescaped keys and values, will NEVER work. http://jsonlint.com/
    If your server accept this “sort of kind of JSON” but does not accept the second one in your example your server is broken.

    My server sees JSON data as “{myrequest:myTest,reqid:44,data:{name:test}}”

    Your server sees a string. When you will try to parse it into JSON it will produce an error or garbage.

    It sees it as “{\”bbrequest\”:\”BBTest\”,\”reqid\”:\”44\”,\”data\”:{\”name\”:\” test\”}}”

    No this is how it’s printed via Ruby’s Object#inspect. You are printing the return value of inspect somewhere and then trying to judge whether it’s valid JSON – it is not, since this string you’ve pasted in is made to be pasted into the interactive ruby console (irb) or into a ruby script, and it contains builtin escapes. You need to see your JSON string raw, just print the string instead of inspecting it.

    I think your server is either broken or not finished yet, your curl example is broken and your ruby script is correct and will work once the server is fixed (or finished). Simply because

      irb(main):002:0> JSON.parse("{\"bbrequest\":\"BBTest\",\"reqid\":\"44\",\"data\":{\"name\":\" test\"}}")
            # => {"bbrequest"=>"BBTest", "reqid"=>"44", "data"=>{"name"=>" test"}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.