0
我試圖連接到一個Rails服務器,但我不斷收到響應使用TCPSocket通過Ruby連接到Rails服務器。獲得「需要長度的WEBrick :: HTTPStatus :: LengthRequired」。請幫忙嗎?
Length Required WEBrick::HTTPStatus::LengthRequired
我使用的TCPSocket連接到服務器。
require 'socket'
host = 'localhost'
port = 3000
path = '/books/show'
#Path of the controller and action to connect to
request = "POST #{path} HTTP/1.0\r\n\r\n "
socket = TCPSocket.open(host,port)
socket.print(request)
我懷疑它的內容長度指定
socket.puts "content-length: 206\r\n"
#write response from server to html file
File.open('test2.html', 'w') do |res|
while (response_text = socket.gets)
res.puts "#{response_text}"
end
end
socket.close
任何幫助的方式嗎?
謝謝@SamRuby,對點。 –