有关使用邮递员二元身体时图像变成什么的问题

詹崇宗

当您在邮递员中发送带有二进制主体类型的图像文件时,该图像在发送时如何编码或在发送时变成什么图像?它是以字节数组,字节字符串,二进制字符串或其他形式发送的吗?

樱桃DT

它作为原始字节发送。只是数据保持原样。没有编码。它与相同,raw但是您可以指定一个文件而不使用文本框(因为文本框已经限制了您可以放入的文本框)。

邮递员的要求:

在此处输入图片说明

原始文件gif,用于比较(HxD的屏幕截图):

在此处输入图片说明

发送的数据(来自SmartSniff的屏幕截图):

在此处输入图片说明

Text representation (screenshot from SmartSniff as well):

在此处输入图片说明

You can see that after the headers, the original GIF file is appended as-is (starting at offset 0x116 in the hex dump).


Additional Information

Addressing your comment:

Is it like a byte string?

All network communication is a stream of bits grouped into octets (bytes). I don't know what you mean by the term "byte string", but the data here is just transmitted without modification, every bit stays the same. (On a protocol (HTTP) level, that is. Of course there is all the remaining network stack below that which splits your data into packets and such.)

The Python bytes literal b'\x41\x42\x43' and the Python string 'ABC' and the bytes 41, 42 and 43 (when viewed in hexadecimal notation) in succession all represent the same thing in some way. At the end, you get a handful of zeroes and ones and those are stored/sent/whatever. (Yes it gets complicated with Non-ASCII literals but still the b'\xAB' notation is just a way to represent bytes with given values.)

would the image being sent be like b'...'?

That's sort of the wrong question, it doesn't have any meaningful answer.

Example: The letter A is normally represented by a byte with value 41 (hex - 65 in decimal), or 01000001 in binary. Those 8 bits are the information that is sent. If you write b'\x41' in Python you get the same thing - one byte with the bits 01000001. So it doesn't make sense to ask if the A is sent as b'\x41' or not, unless you mean the actual characters b'\x41' as you would type them into your code file - in that case no, because those would be 7 bytes and it doesn't make sense to do that if we could just send one byte (consisting of the value representing A) instead.

Say if I was to send the image using an http client what data format would I put the image in to send it to an api that is like sending the image with a binary body in postman?

在Python中,您有几种表示原始二进制数据的方法,发送文件的内容时,您可以使用binary模式读取文件并将数据传递给HTTP请求:

requests.post(
  url='http://httpbin.org/post',
  data=open('./image.gif', 'rb').read(),
  headers={'Content-Type': 'application/octet-stream'}
)

在node.js中,您可以将此类数据存储在一个Buffer对象中。在C#中,您将使用字节数组(Byte[])。大多数语言都有某种方式来表示字节链,就像这样,还没有附加含义。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

与邮递员发帖时Req没有身体

如何消除 /etc/mail.log 中与已失效的邮递员安装有关的错误和警告?

为什么我在使用Spring Boot Application的邮递员中没有收到错误消息

使用邮递员创建索引时在Elasticsearch中出错

ADLS Gen-2。从有关邮递员创建新文件系统的PUT请求中获取AuthorizationPermissionMismatch错误

邮递员:如何设置邮递员使用“ pm”代替“邮递员”

使用邮递员测试具有 RequestParam 的休息服务

邮递员身体原始请求到Swift Alamofire

邮递员:从身体中提取价值

邮递员授权问题(代理设置?)

从邮递员发送json的问题

尝试使用“邮递员”并在设置基本访问身份验证标头时遇到问题

邮递员,Python以及将图像和元数据传递到Web服务

有条件的二元运算符,是什么问题?(贝壳)

无法与邮递员发帖,为什么?

.htaccess与图像处理有关的问题

Express中间件在使用邮递员时不触发,但在与浏览器连接时有效

当带有邮递员的相同请求正常工作时,使用Symfony HttpClient的请求返回代码0

api要求如何使用邮递员

使用邮递员发出“ _doPostBack”请求

使用邮递员输出随机值

无法在邮递员中使用服务

无法使用邮递员查询数据

使用邮递员接受zip文件

在邮递员中使用集合变量

邮递员要求使用“全局” URL

使用邮递员上传图片

从邮递员发送带有图像/文件的嵌套 JSON 数据:Django REST 框架

通过邮递员发送带有图像的POST json对象