我最近遇到了植入Spring的REST Web服务,它接受了字节数组作为输入。但令我困惑的是,REST是通过使用HTTP协议实现的,而HTTP只以字符串格式传输数据,它可能是JSON,HTML,XML或简单文本。然后如何在服务器端传输和接受字节数组。我知道Spring消息转换器用于将输入转换为适当的数据类型,但我的问题基本上是关于HTTP数据传输而不是Spring实现...谢谢
答案 0 :(得分:0)
HTTP transfer the data in string format only
As you say, it uses string format. Actually String
is just an interpretation of data contained in a byte[]
. Data is always transferred/stored in form of a byte[]
. If you then read this data you convert it to something else like a text or maybe a picture by interpreting single bytes
as a character or maybe a pixel. So in this case Spring simply gives you the raw data of the request.