我正在尝试使用net / http将工作的curl代码转换为ruby。 我收到一个由对等方(Errno :: ECONNRESET)重置的连接错误,我不确定为什么。 这是工作卷发:
curl -X POST -u "apikey:MYAPIKEY" -H "Content-Type:application/json" -d '{"url":"https://www.cnn.com/2020/08/20/politics/trump-ballot-florida-lawsuit/index.html","features": {"sentiment": {}, "categories": {},"concepts": {},"entities": {},"keywords": {} } }' "https://gateway-wdc.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-19"
红宝石
require 'net/http'
require 'uri'
uri = URI.parse('https://gateway-wdc.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-19')
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.basic_auth("apikey", "MYAPIKEY")
request.set_form_data({
"url" => "https://www.cnn.com/2020/08/20/politics/trump-ballot-florida-lawsuit/index.html",
"features" => "{'sentiment': {}, 'categories': {},'concepts': {},'entities': {},'keywords': {} } }"
})
request.add_field("Content-Type", "application/json")
response = http.request(request)
puts response.inspect
谢谢。