简体   繁体   English

如何访问 http 请求的正文

[英]How to access the body of an http request

I am making an http request to hit an endpoint using Python's request library as shown below:我正在使用 Python 的请求库发出 http 请求以访问端点,如下所示:

r = requests.get('http://127.0.0.1:...',data = {...})

If i model this request on Postman i get as a result an object like shown below:如果我 model 这个请求在 Postman 我得到一个 object 结果如下所示:

{"o":1}

which is what my endpoint returns.这是我的端点返回的。

However if a manually do the request i can't access this object.The request reaches my server just fine like a erquest from postman.但是,如果手动执行请求,我将无法访问此 object。请求到达我的服务器就像来自 postman 的请求一样。

I tried r.json() but this prints an int value of 1015 which i don't understand how it is generated.Is it an error code?我试过r.json()但这会打印一个1015的 int 值,我不明白它是如何生成的。它是错误代码吗? I've been stuck in this for a while,any ideas?我已经被困了一段时间了,有什么想法吗?

  • Use r.content to get the binary data使用r.content获取二进制数据
  • Use r.text to get the string (using an encoding such as UTF-8)使用r.text获取字符串(使用 UTF-8 等编码)
  • Use r.json to get the json dictionary使用r.json得到 json 字典

I don't know why you are getting 1015 - this may be specific to your output.我不知道你为什么会得到 1015 - 这可能特定于你的 output。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM