使用javascript将API与API键一起使用

使用javascript将API与API键一起使用,javascript,api,Javascript,Api,所以我想从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 = Unire

所以我想从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();
Task response=Unirest.post(“https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies")
.标题(“X-Mashape-Key”、“huni7LtgROmshd8R87ecu5BQdcY1p1Cf0Uijsn5mgXEaDEtsbP”)
.header(“内容类型”、“应用程序/x-www-form-urlencoded”)
.header(“接受”、“应用程序/json”)
.asJson();

我想知道如何使用javascript执行相同的任务,以及该示例中api的URL是什么。

您可以使用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 }
});

谢谢,但是。。在代码的第5行..这是Mashape不可Mashable,以防有人复制它。。。。。顺便说一句,你让我浪费了不必要的时间去寻找问题所在。。还是非常感谢。。。更新:我仍然可以通过浏览器中的URL访问该api吗?因为该api似乎在寻找帖子,所以您必须使用类似于
邮递员的东西。这样您就可以发送正确的标题。谢谢你的拼写错误。我在我的平板电脑上这么做,所以它看起来像是自动更正的。