【问题标题】:Test GET and POST calls测试 GET 和 POST 调用
【发布时间】:2019-03-29 20:48:46
【问题描述】:

我需要针对 NGINX 服务器测试 POST 和 GET 调用。

我需要捕获错误代码并验证响应。我可以通过点击 localhost:8080 来测试 GET 请求(NGINX 在 docker 上运行,暴露 8080),但我不确定如何测试 POST 调用。

我们可以构造一个虚拟请求并测试 POST 调用吗? NGINX 使用默认页面运行。

【问题讨论】:

标签: python python-2.7


【解决方案1】:

以下是在 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) 

【讨论】:

    猜你喜欢
    • 2020-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 2019-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多