Why my http POST request doesn't go well?

Posted by 0x90 on Stack Overflow See other posts from Stack Overflow or by 0x90
Published on 2012-12-07T09:51:56Z Indexed on 2012/12/07 11:04 UTC
Read the original article Hit count: 189

Filed under:
|
|

I am trying to make this POST request in ruby. but get back #<Net::HTTPUnsupportedMediaType:0x007f94d396bb98> what I tried is:

require 'rubygems'
require 'net/http'
require 'uri'
require 'json'

auto_index_nodes =URI('http://localhost:7474/db/data/index/node/')

request_nodes = Net::HTTP::Post.new(auto_index_nodes.request_uri)
http = Net::HTTP.new(auto_index_nodes.host, auto_index_nodes.port)

request_nodes.add_field("Accept", "application/json")

request_nodes.set_form_data({"name"=>"node_auto_index",
                            "config" => {
                            "type" => "fulltext",
                            "provider" =>"lucene"} ,
                            "Content-Type" => "application/json"
                            })


response = http.request(request_nodes)

Tried to write this part:

"config" => {
             "type" => "fulltext",
             provider" =>"lucene"} ,
             "Content-Type" => "application/json"
            }

like that:

"config" => '{
              "type" => "fulltext",\
              "provider" =>"lucene"},\
              "Content-Type" => "application/json"\
              }'

this try didn't help either:

request_nodes.set_form_data({"name"=>"node_auto_index",
                            "config" => '{ \
                            "type" : "fulltext",\
                            "provider" : "lucene"}' ,
                            "Content-Type" => "application/json"
                            })

© Stack Overflow or respective owner

Related posts about ruby

Related posts about post