开发者

OAuth issue in Google AppEngine developing

开发者 https://www.devze.com 2023-03-04 07:01 出处:网络
i have encountered a weird problem in Google App Engine developing, every time is carry a body content in my post request, app engine failed to auth my account, but get request works.

i have encountered a weird problem in Google App Engine developing, every time is carry a body content in my post request, app engine failed to auth my account, but get request works. can anybody help me? i'm using oauth library ChromeExOAuth in chrome extension developing.

    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(re开发者_开发百科sp, xhr){
            console.log("responding from test server", xhr.responseText);
        }, request);
    });


For POST requests you must pass the oauth parameter url-encoded in the request body. The relavant code in the SDK is this (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

See that the query is only parsed in GET requests. For POST, it must be in the body.

0

精彩评论

暂无评论...
验证码 换一张
取 消