我有一些 PHP 代码查询 MySQL 数据库的计数。
通过浏览器查询时,我得到以下输出:
{"count":"123"}
我还有一个 Ruby 脚本,它通过 Net::HTTP 执行相同的 PHP 脚本,但输出不同:
{"count"=>"123"}
为什么是这样?
//The URL
uri = URI.parse("http://lab/count.php")
http = Net::HTTP.new(uri.host, uri.port)
//Request URL
request = Net::HTTP::Get.new(uri.request_uri)
//Basic authentication
request.basic_auth("user1", "secret")
response = http.request(request)
//Response
response = JSON.parse(response.body)
puts results
//Value 'count'
count = JSON.parse(response.body)[0]
puts count
谢谢。