【发布时间】:2019-03-29 20:48:46
【问题描述】:
我需要针对 NGINX 服务器测试 POST 和 GET 调用。
我需要捕获错误代码并验证响应。我可以通过点击 localhost:8080 来测试 GET 请求(NGINX 在 docker 上运行,暴露 8080),但我不确定如何测试 POST 调用。
我们可以构造一个虚拟请求并测试 POST 调用吗? NGINX 使用默认页面运行。
【问题讨论】:
标签: python python-2.7
我需要针对 NGINX 服务器测试 POST 和 GET 调用。
我需要捕获错误代码并验证响应。我可以通过点击 localhost:8080 来测试 GET 请求(NGINX 在 docker 上运行,暴露 8080),但我不确定如何测试 POST 调用。
我们可以构造一个虚拟请求并测试 POST 调用吗? NGINX 使用默认页面运行。
【问题讨论】:
标签: python python-2.7
以下是在 python 中向端点发出 post 请求的一种方法
import requests
API_ENDPOINT = "http://pastebin.com/api/api_post.php"
data = {param1:value1,
param2:value2}
#sending post request and saving response as response object
r = requests.post(url = API_ENDPOINT, data = data)
#extracting response text
pastebin_url = r.text
print("The pastebin URL is:%s"%pastebin_url)
【讨论】: