python - 了解 API 响应正文 - Plumber 和 Python
问题描述
我试图了解 API 响应体到底是什么。与标题,状态代码有何不同。我想对传输的位或返回的字符串有非常低的理解。
这是我在 Plumber API 中所做的:
#* @param msg The message to echo back.
#* @get /echo
function(msg="", res){
res$status <- 200
}
现在当我用 Python 检查它时
import requests
r = requests.get(url = 'myurl')
r.text
输出:
'[200]'
还
r.status_code
返回:
200
看起来响应的主体是'[200]'
现在我更改我的 API 以返回:
#* @param msg The message to echo back.
#* @get /echo
function(msg="", res){
res$status <- 200
res$body <- "This is body of the response"
}
在python中我得到:
r = requests.get(url = 'myurl')
r.text
输出:
'["This is body of the response"]'
和
r.status_code
返回
200
那么,在第二种情况下200
不再是身体的一部分?那么响应的具体内容是什么。
解决方案
推荐阅读
- reactjs - 如何从深层嵌套子组件调用方法
- windows - 如何将 CCM_UserAffinity 输出格式化为 tyoe Microsoft.PowerShell.Commands.LocalPrincipal
- c# - IoErr (10), message = System.Data.SQLite.SQLiteException (0x800007FF): System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn) 的磁盘 I/O 错误
- javascript - 如何用玩笑在 redux 中模拟异步动作创建者
- javascript - 遇到this.state不是函数错误
- machine-learning - 要在 Keras 模型中传递什么数据类型以适应?
- ajax - Internet Explorer XMLHttpRequest 中的 Cors 问题:网络错误 0x80070005,访问被拒绝
- angular - 想要在LinkedIn中分享帖子特定的og:image
- spring - 将 spring-boot 应用程序提交给 spark 时出错
- git - git 可以按合并到分支的顺序显示文件吗