1

我需要使用三个参数和一个由 512 个字节组成的正文进行发布。我可以得到正确的身体,但我似乎无法获得要采用的参数:

require 'net/http'

@ip_address = Array['cueserver.dnsalias.com']
@cueserver = 0
@playback = 'p1'

def send_cuescript(data) 

  params = {'id' => '1', 'type' => "20",'dst' => 'RES'  }

  begin
    url = URI.parse('http://'+ @ip_address[@cueserver] + '/set.cgi')
    http = Net::HTTP.new(url.host, url.port)

    response, body = http.post(url.path, params, data)

   rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
          Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
   end        
 response_array = []
 puts 'got this value: ' + response.to_s
 response.body.each_byte { |e| response_array.push(e.to_s(16))}
end

data_array = Array.new(512, "\x80")
send_cuescript(data_array.join)

我收到来自 initialize_http_header 的错误。我知道必须有一种方法可以分别设置参数和主体,但我似乎找不到任何对此的参考。

4

1 回答 1

0

为什么必须在 url 中发送部分参数而在正文中发送部分参数?如果您必须这样做,请尝试

url = URI.parse('http://'+ @ip_address[@cueserver] + '/set.cgi?' + params.to_param)

PS:to_param 来自积极支持。如果您不使用主动支持,则需要自己编写。

于 2012-11-11T15:24:01.423 回答