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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:29:33+00:00 2026-06-08T21:29:33+00:00

I am trying to write a simple http post which will send a json

  • 0

I am trying to write a simple http post which will send a json body to a restful api. I am using the following code:

data = {'EmailAddress' => email, 'Name' => 'bobby', 'CustomFields' => [ {'Key' => 'Country', 'Value' => 'canada'}, {'Key' => 'City', 'Value' => 'vancouver'} ], 'Resubscribe' => true }.to_json

require 'net/http'
net = Net::HTTP.new("api.createsend.com", 80)
request = Net::HTTP::Post.new("/api/v3/subscribers/#{@list}.json")
request.basic_auth(@api, 'magic')
request.set_form_data(:body => data)

response = net.start do |http|
http.request(request)
end
puts response.code
puts response.read_body

The trouble I am having is the body is going to the server as a string and not as hex. Here is what I am sending:

body=%7b%22EmailAddress%22%3a%223%40blah.com%22%2c%22Name%22%3a%22bobby%22%2c%22CustomFields%22%3a%5b%7b%22Key%22%3a%22Country%22%2c%22Value%22%3a%22canada%22%7d%2c%7b%22Key%22%3a%22City%22%2c%22Value%22%3a%22vancouver%22%7d%5d%2c%22Resubscribe%22%3atrue%7d

Here is what I want to send:

{
  "EmailAddress": "3@blah.com",
  "Name": "bobby",
  "CustomFields" : [
    {
      "Key":"Country",
      "Value":"canada"
    },
    {
      "Key":"City",
      "Value":"vancouver"
    }
  ],
  "Resubscribe": true
}

How can I pack this data so it is not going out as a string?

  • 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-08T21:29:34+00:00Added an answer on June 8, 2026 at 9:29 pm

    Instead of:

    request.set_form_data(:body => data)
    

    Try it like this:

    request.body = data
    

    net/http should not be uri-encoding the post body, if you see that happening then maybe something else along the way is doing it or maybe you’re just mistaken.

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

Sidebar

Related Questions

I am trying to write some simple code which will read a text file
I am trying to write a simple news feed aggregator. I am using http://code.google.com/p/feedparser/
I'm trying to write a simple program which uses libcurl to perform HTTP POST
I'm trying to write a simple chat bot for Adium, that will post lol
I'm trying to write a simple HTTP web server using c, but I keep
I trying to write a simple function to call unmanaged code from managed code.
I'm trying to write a simple code in Java to connect to a memcache
I am trying to write a simple Java function that will take a list
I am trying to write a simple application in Python which uses SimpleCV for
I am trying to write a simple Http client application in Java and am

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.