卷曲:如果我使用curl -data-binary发送Java InputStream的数据如何解释数据?
我有一台在Java上写的服务器,该服务器当前正在运行
http:// localhost:8080
源代码对我隐藏,但我知道所有端点均由Java Httpexchange类处理,例如端点:
http:// localhost:8080/generate/init
将会像这样处理:
public void init(HttpExchange httpex) throws IOException {
...
}
帖子请求是这样处理的:
byte post_data = (byte) httpex.getRequestBody().read();
我的问题是,当我从命令行进行操作时:
echo -e '\x03' | curl -X POST -i --data-binary @- http://localhost:8080/generate/init
我知道的下一件事是这样处理的 post_data的值? 据我了解,卷发会完全按原样发送'\ x03':
\ x03
和java httpexchange方法getRequestbody()将返回其输入流,其中read()将将该输入式转换为int。众所周知,Java不会将十六进制解释为“ \ x03”,而是使用Unicode'\ u0003'。因此,我害怕将错误的数据发送到我的服务器中。
如果我对卷曲 - 二进制二进制,请纠正我!我只是希望 可以肯定的是,我通过邮政请求和服务器传递数字“ 3” 将其解释为数字3,但在字节((字节)3)
中将其解释为
I have a server, written on Java, which is currently running on a
http://localhost:8080
Source code is hidden from me, but I know that all endpoints are handled by Java HttpExchange class, for example endpoint:
http://localhost:8080/generate/init
will be handled like that:
public void init(HttpExchange httpex) throws IOException {
...
}
The next thing I know is that incoming POST requests are handled like that:
byte post_data = (byte) httpex.getRequestBody().read();
My question is, that when I do from a command-line:
echo -e '\x03' | curl -X POST -i --data-binary @- http://localhost:8080/generate/init
What will be the value of post_data?
As I understand curl will send '\x03' exactly as it is:
\x03
And Java HttpExchange method getRequestBody() will return InputStream of it, where read() will translate that InputStream into int. As much as I know, Java doesn't interpret HEX as '\x03', instead it uses Unicode '\u0003'. Therefore I'm afraid of sending wrong data into my server.
If I'm wrong about curl --data-binary, please correct me! I just wish
to be sure, that I pass number "3" by POST request and server
interprets it as number 3, but in bytes ((byte) 3)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论