Rails サーバーに接続しようとしていますが、取得し続ける応答は
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