5

我正在使用 Net::HTTP 发出 HTTP 请求。我收到错误“HTTP 请求路径为空”,但我强烈认为不是。代码如下:

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

错误是:

/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'

谁能指出我的错误?

4

1 回答 1

16

当我没有包含尾随时,我收到了类似的错误/。一旦我这样做,一切都很好。

根据您共享的信息,我只能假设您的message变量没有。

于 2013-07-17T19:53:59.507 回答