它是一个 RESTAPI,我需要向 onesignal 发送获取请求。
网址 = https://onesignal.com/api/v1/apps
他们提到的只是:
curl --include \
--header "Authorization: Basic your_key_here" \
https://onesignal.com/api/v1/apps
我尝试过这样的事情:
def index
url = URI.parse('https://onesignal.com/api/v1/apps?apikey=mykey')
req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
puts res.body
end
但这不起作用。结果应该是 json。
我收到此错误:
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>