卷曲:如果我使用curl -data-binary发送Java InputStream的数据如何解释数据?

发布于 2025-01-30 08:54:09 字数 921 浏览 0 评论 0原文

我有一台在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文