Error Converting Curl Request to Net::HTTP Error Converting Curl Request to Net::HTTP curl curl

Error Converting Curl Request to Net::HTTP


set_form_data will encode the request payload as www-form-encoded. You need to simply assign the body directly.

uri = URI('https://xxxxxxxx.ws/authenticate')https = Net::HTTP.new(uri.host,uri.port)https.use_ssl = truereq = Net::HTTP::Post.new(uri)req['Content-Type'] = 'application/json'req.body = { username: 'foo', password: 'bar' }.to_jsonres = https.request(req)


You're trying to send username and password as form-encoded parameters (set_form_data) when the curl command is sending them as json. Try setting the content body of the request to the json shown in the command.