How to transfer a post request in curl into a ruby script?
Posted
by
0x90
on Stack Overflow
See other posts from Stack Overflow
or by 0x90
Published on 2012-12-01T14:21:51Z
Indexed on
2012/12/01
17:04 UTC
Read the original article
Hit count: 235
I have this post
request:
curl -i -X POST \
-H "Accept:application/json" \
-H "content-type:application/x-www-form-urlencoded" \
-d "disambiguator=Document&confidence=-1&support=-1&text=President%20Obama%20called%20Wednesday%20on%20Congress%20to%20extend%20a%20tax%20break%20for%20students%20included%20in%20last%20year%27s%20economic%20stimulus%20package" \
http://spotlight.dbpedia.org/dev/rest/annotate/
How can I write it in ruby? I tried this as Kyle told me:
require 'rubygems'
require 'net/http'
require 'uri'
uri = URI.parse('http://spotlight.dbpedia.org/rest/annotate')
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data({
"disambiguator" => "Document",
"confidence" => "0.3",
"support" => "0",
"text" => "President Obama called Wednesday on Congress to extend a tax break for students included in last year's economic stimulus package"
})
request.add_field("Accept", "application/json")
request.add_field("Content-Type", "application/x-www-form-urlencoded")
response = http.request(request)
puts response.inspect
but got this error:
#<Net::HTTPInternalServerError 500 Internal Error readbody=true>
© Stack Overflow or respective owner