Why do I get Net::HTTP “request path is empty” error?

自古美人都是妖i 提交于 2019-12-06 08:19:27

问题


I'm using Net::HTTP to make a HTTP request. I get the error "HTTP request path is empty", but I strongly feel that it is not. The code is below:

REQUEST_IP = "localhost"
REQUEST_PORT = "8081"
REQUEST_PATH = "myweb/rest"

def customServiceMailAndMessageRequest user_id, message

  url = 'http://' + REQUEST_IP + ":" + REQUEST_PORT + "/" + REQUEST_PATH + '/users/' + user_id + '/messages/sendMailAndMessage?message=' + message
  uri = URI(url)

  request = Net::HTTP::Get.new(uri.path)
  request['Content-Type'] = 'application/json'
  request['Accept'] = 'application/json'

  response = Net::HTTP.new(uri.host,uri.port) do |http|
    http.request(request)
  end

  puts response

end

The error is:

/usr/lib/ruby/1.8/net/http.rb:1478:in `initialize': HTTP request path is empty (ArgumentError)
    from /usr/lib/ruby/1.8/net/http.rb:1596:in `initialize'

Can anyone point towards my mistake?


回答1:


I received a similar error when I didn't include a trailing /. As soon as I did, all was well.

From the information that you've shared, I can only assume that your message variable doesn't have that.



来源:https://stackoverflow.com/questions/16018552/why-do-i-get-nethttp-request-path-is-empty-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!