我在Google App Engine开发中遇到了一个奇怪的问题,每次都在我的帖子请求中携带正文内容,app引擎无法验证我的帐户,但获取请求有效。 有谁能够帮我?我在chrome扩展开发中使用oauth库ChromeExOAuth。
oauth.authorize(function(){
var request = {
'method': 'POST',
'headers': {
"Content-Type" : "application/x-www-form-urlencoded"
},
'parameters': {
},
'body': "a=b"
};
oauth.sendSignedRequest("http://mytabshub.appspot.com/tabshub", function(resp, xhr){
console.log("responding from test server", xhr.responseText);
}, request);
});
答案 0 :(得分:0)
对于POST请求,您必须在请求正文中传递url-encoded的oauth参数。 SDK中的相关代码是这个(dev_appserver_oauth.py):
def _Parse(self, request, base_env_dict):
"""Parses a request into convenient pieces.
Args:
request: AppServerRequest.
base_env_dict: Dictionary of CGI environment parameters.
Returns:
A tuple (method, path, headers, parameters) of the HTTP method, the
path (minus query string), an instance of mimetools.Message with
headers from the request, and a dictionary of parameter lists from the
body or query string (in the form of {key :[value1, value2]}).
"""
method = base_env_dict['REQUEST_METHOD']
path, query = dev_appserver.SplitURL(request.relative_url)
parameters = {}
if method == 'POST':
form = cgi.FieldStorage(fp=request.infile,
headers=request.headers,
environ=base_env_dict)
for key in form:
if key not in parameters:
parameters[key] = []
for value in form.getlist(key):
parameters[key].append(value)
elif method == 'GET':
parameters = cgi.parse_qs(query)
return method, path, request.headers, parameters
请参阅仅在GET
次请求中解析查询。对于POST
,它必须在身体中。