所以我想从mashape.com访问api,但链接总是给我
{"message":"Missing Mashape application key. Go to http:\/\/docs.mashape.com\/api-keys to learn how to get your API application key."}
以下网站提供的示例,说明如何使用.Net来请求api:
Task<HttpResponse<MyClass>> response = Unirest.post("https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies")
.header("X-Mashape-Key", "huni7LtgROmshd8R87ecu5BQdcY1p1Cf0Uijsn5mgXEaDEtsbP")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Accept", "application/json")
.asJson();
我想知道如何使用javascript执行相同的任务,以及该示例中api的URL是什么。
答案 0 :(得分:0)
您可以使用Ajax执行此操作:如果您使用的是jQuery:
$.ajax({
url: 'https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies",
method: 'post',
header: {
'X-Mashape-Key': 'your api key',
'Content-type': 'application/x-www-form-rule coded',
'Accept': 'application/json'
},
crossDomain: true,
success: function(data) { doSomething with your data here }
});