import logging
import azure.functions as func
from urllib.parse import parse_qs
def main(req: func.HttpRequest) -> func.HttpResponse:
# This function will parse the response of a form submitted using the POST method
# The request body is a Bytes object
# You must first decode the Bytes object to a string
# Then you can parse the string using urllib parse_qs
logging.info("Python HTTP trigger function processed a request.")
req_body_bytes = req.get_body()
logging.info(f"Request Bytes: {req_body_bytes}")
req_body = req_body_bytes.decode("utf-8")
logging.info(f"Request: {req_body}")
first_name = parse_qs(req_body)["first_name"][0]
last_name = parse_qs(req_body)["last_name"][0]
email = parse_qs(req_body)["email"][0]
cell_phone = parse_qs(req_body)["cell_phone"][0]
return func.HttpResponse(
f"You submitted this information: {first_name} {last_name} {email}
{cell_phone}",
status_code=200,
)
3条答案
按热度按时间q7solyqu1#
下面是HTTP POST请求触发的Function App的示例代码。
一月一日
一个月一个月
看看这个Python POST请求的GitHub示例:https://github.com/yokawasa/azure-functions-python-samples/tree/master/v2functions/http-trigger-onnx-model
wrrgggsh2#
此代码段可以工作:https://github.com/yuenci/Azure-Functions-Request-CORS
确保允许post方法
6tr1vspr3#
提交的表单中的数据将是一个Bytes对象。您必须将其转换为字符串,然后分析参数。此示例代码处理基本联系人信息表单的提交。