码迷,mamicode.com
首页 > Windows程序 > 详细

使用google API之前需要對input 做什麼 安全性的處理?

时间:2017-07-18 00:01:52      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:error   put   tle   str   action   show   小应用   .com   .json   

我正要使用node.js 和 google map api做一个小应用,Google MAP API的使用URL如下:

https://maps.googleapis.com/maps/api/place/textsearch/json?query=KEY+WORDS&key=YOUR_API_KEY

KEY WORDS的部分将是我在我的应用上id="keywords"这个input的value

HTML CODE:

<form action="/api/googlemap" method="POST">
    <input id="keywords" diname="keywords" type="text"></input>
</form>

传到/api/googlemap后我使用node.js 的 request当作我的http client去跟google api要资料

var request = require(‘request‘);
router.get(‘/api/googlemap‘,function (req, res) {
    var keywords = req.body.keywords;
    var url = ‘https://maps.googleapis.com/maps/api/place/textsearch/json?query=‘+keywords+‘&key=myapikey‘;
    request(‘url‘, function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Show the HTML for the Google homepage.
  }

  else{
    res.json(response);
}

})
    
});

请问我这样对keywords的处理是不是不够安全?
在node.js 上我应该对 req.body.keywords 做什麽样的处理之后再跟google api再使用request和API要资料?

我注意到value在URL上,google给的example对 (空格)都是使用+替代,而如果我在chrome浏览器上,URL输入空白后会自动换成 %20,那我在node.js需要使用replace(" ","+") 将 (空格)换成+吗?

谢谢


使用google API之前需要對input 做什麼 安全性的處理? >> node.js

这个答案描述的挺清楚的:
http://www.goodpm.net/postreply/node.js/1010000008220193/使用googleAPI之前需要對input做什麼安全性的處理.html

使用google API之前需要對input 做什麼 安全性的處理?

标签:error   put   tle   str   action   show   小应用   .com   .json   

原文地址:http://www.cnblogs.com/scrumme/p/7197616.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!