[英]How to remove api_key from url in angularjs
I need an apikey to be able to send a get request to a REST api. 我需要一个apikey才能将get请求发送到REST api。 The request will look something like this - 该请求将如下所示-
$http.get( http://api.randomsite.com/page.json?api_key=apikey123 ) $ http.get( http://api.randomsite.com/page.json?api_key=apikey123 )
This will give me data in json format. 这会给我json格式的数据。
But i dont want the api key to appear in the url due to safety reasons. 但是出于安全原因,我不希望api键出现在url中。 Is it possible to remove the api_key and somehow still make the get request work? 是否可以删除api_key并以某种方式仍然使get请求起作用? Like this - 像这样 -
$http.get( http://api.randomsite.com/page.json ) $ http.get( http://api.randomsite.com/page.json )
I read its something to do with headers, but i tried a lot and cannot figure it out. 我读了一些与标题有关的内容,但尝试了很多,却无法弄清。 Help :/ 救命 :/
Well, if you want to hide the API_KEY, there's few ways to do this 好吧,如果您想隐藏API_KEY,则有几种方法可以做到这一点
POST
, although this is only a half measure, as anyone could look into the POST
body and see what it is. 通过POST
发送它,尽管这只是一半,因为任何人都可以查看POST
正文并查看它是什么。 Nevertheless, the way you do it is by 不过,您的做法是 $http.post("api/salesapi.php/sales/", {API_KEY:xx}, {headers: ... });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.