Because I am limited to working off a scripting environment of a packaged application with a restricted set of Ruby 1.9.3 base libraries, I can only use TCPSocket to access the internet. In particular, I cannot use net/http or json or uri...
Nonetheless, I would like to call an Azure ML Model Endpoint.
Below is what I am trying to do, but unfortunately I get an error from "socket.gets":
Errno::ECONNRESET (An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:3 )
require 'socket'
data = '{
"Inputs": {
"data": [
{
"Column1": "example_value",
"Column2": 0
}
]
},
"GlobalParameters": {
"method": "predict"
}
}'
# Send the HTTP request
socket = TCPSocket.open('xxxxx-ml-yyyyy.northeurope.inference.ml.azure.com', 443)
request = "POST 'xxxxx-ml-yyyyy.northeurope.inference.ml.azure.com HTTP/1.1\r\n"
request += "Host: xxxxx-ml-yyyyy.northeurope.inference.ml.azure.com\r\n"
request += "Content-Type: application/json\r\n"
request += "Authorization: Bearer 1234567890abcdefghjklmnopqrstuvwx\r\n"
request += "Content-Length: #{data.bytesize}\r\n"
request += "\r\n"
request += data
socket.print(request)
# Get the response
response = ""
while line = socket.gets
response += line
end
# Close the socket
socket.close
puts response
(reproducible with irb 2.5.3)
Calling the Endpoint through Python from the same machine works perfectly. So I suppose smth is wrong with my HTTP request?