无效的流标头:47455420-Java输入流 [英] invalid stream header: 47455420 - Java Input Stream

查看:135
本文介绍了无效的流标头:47455420-Java输入流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello World!

当前,我正在编写一个简单的客户端/服务器应用程序,该应用程序使用套接字进行通信.我的客户端和我的Server应用程序可以正常工作,但是如果我尝试使用真正的Web浏览器(例如Mozilla Firefox)查询我的Server应用程序,则会出现异常.

Currently I'm writing a simple Client/Server application which uses sockets to do the communitcation. My Client and my Server application are working fine with each other but if I try to query my Server application with a real web-browser (like Mozilla Firefox), then it comes to an exception.

我认为我的流与Mozilla Firefox不兼容.这个小代码行始终会导致IOException并显示错误消息"invalid stream header:47455420".

I think that my streams are not compatible with Mozilla Firefox. This little code line always leads to an IOException with the error message "invalid stream header: 47455420".

我尝试从Firefox通过以下方式连接: http://localhost:7777/some-webpage.html

From Firefox I try to connect via: http://localhost:7777/some-webpage.html

这是我的代码:

server = new ServerSocket(7777);
Socket socket = server.accept();
try
{
    ObjectInputStream inputStream = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
}
catch (IOException ex)
{
    System.out.println("This exception happens :-(");
    System.out.println(ex.getLocalizedMessage());
}

有人知道为什么会这样吗? 乐于助人.

Does anybody know why this happens? Help is seen with pleasure.

问候

本尼

推荐答案

ObjectInputStream需要二进制格式.您无法使用网络浏览器来生成其读取的二进制格式. Web浏览器将使用HTTP协议,而您的服务器根本不希望使用该协议.

The ObjectInputStream expects a binary format. You can't use a web browser to produce the binary format that it reads. The web browser will talk HTTP protocol, and your server is not expecting that at all.

您可能需要了解Web服务.您可能会在 CXF 中找到对JAX-RS的支持,对于您想做的事情很方便.

You probably need to learn about web services. You might find the JAX-RS support in CXF convenient for what you seem to want to do.

要仅使用HTTP,要做的最简单的事情就是实现一个servlet:google将是您了解它们的朋友.

To just drop in to HTTP, the minimal thing to do is implement a servlet: google would be your friend in learning about them.

这篇关于无效的流标头:47455420-Java输入流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆