我的服务器 Google App Engine API 代码和我的客户端都使用 python。我已经有很多客户端-服务器 GET 请求在工作,现在是 POST 请求的时候了,但我被卡住了。我的相关客户代码:
service = build("myAPI", "v1", http=http, discoveryServiceUrl=DISCOVERY_URL)
service.updateUser(websafeKey=websafeKey).execute()
Run Code Online (Sandbox Code Playgroud)
我不知道如何构建 POST 请求的正文。在那之后,我将被困在试图弄清楚如何告诉service它以便它可以将请求发送到我的 updateUser API。
POST 请求正文将需要包含一些字符串和几个列表,然后可能包含一个 python Date 对象。
我的updateUserAPI 在 API Explorer 中运行良好 - 我可以updateUser一整天都成功:
USER_POST_REQUEST = endpoints.ResourceContainer(
UserForm, websafeKey=messages.StringField(1),)
@endpoints.method(USER_POST_REQUEST, UserForm,
path='useradmin/{websafeKey}',
http_method='PUT', name='updateUser')
def updateUser(self, request):
"""Update user w/provided fields & return w/updated info."""
return self._updateUserObject(request)
Run Code Online (Sandbox Code Playgroud)