【发布时间】:2016-12-20 13:07:15
【问题描述】:
出于安全原因,我正在将现有的 http.get 请求转换为 http.post 请求。 即使我编写的代码正在运行,我认为它不是很健壮。有没有更好的方法来定义数据对象?
我更喜欢发送字典并在后端阅读它。
示例代码如下。
http.get("/ajax/validate_login.py",{params:{"email":$scope.userEmail,"password":$scope.password}}).then(function(response) {
console.log(response);
});
转换为
$http({ method: 'POST', url: '/ajax/validate_login.py?',
data: 'email=' + $scope.userEmail + '&password=' + $scope.password ,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function(response) {
console.log(response);
});
有没有更好的方法在发布请求中定义数据?
后端代码如下
#!/usr/bin/python
import cgi
import json
import MySQLdb
import MySQLdb.cursors
import hashlib
import sys
form = cgi.FieldStorage()
email=form["email"].value
password = form["password"].value
print "Content-Type: application/json"
print
【问题讨论】:
-
使用$resource而不是$http,有一个好方法可以让工厂使用服务