我通过Ruby调用API,但它给了我HTML响应而不是JSON。当我通过POSTMAN调用相同的api时,它会给出正确的json响应。我的代码和邮递员屏幕截图已附上。
require 'net/https'
require 'json'
uri = URI('https://www.mobifinplus.com/api.php')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'text/json')
req.body = '
{"request_type" : "registration", "first_name" : "test", "last_name" : "test", "country_code_mobile" : "+254", "mobile_no" : "1234567", "id_number" : "1234", "username" : "weratest", "password" : "test", "gender" : "male", "pinnumber" : "1234"}'
res = http.request(req)
puts "response #{res.message}"
puts "response #{res.body}"