请让我知道如何从变量将输入发送到URL路径参数。我确实有关于通过有效负载将输入传递到Query Parameter的想法,但是在API以下使用路径参数,我需要将8,3和+作为变量传递,我不知道我如何通过它们:
http://localhost:8184/messenger/webapi/Calculator/8/3/+
您可以只使用字符串插值来构建URL。在将值放入URL之前,请确保引用值:
from urllib import quote
op1, op2, operator = '8', '3', '+'
url = 'http://localhost:8184/messenger/webapi/Calculator/{}/{}/{}'.format(
quote(op1), quote(op2), quote(operator))