[英]Sending HTTP response with raw sockets, client doesn't receive message
I am trying to send this message entity body to the client. 我正在尝试将此消息实体正文发送给客户端。 But, this message seems to be not transmitted.
但是,此消息似乎未发送。 What possible reason is that results in this situation ?
导致这种情况的可能原因是什么? String message
字串讯息
String message = "HTTP/1.0 404 Not Found\r\n" +
"Server: " +
"Content-type: html" +
"error\r\n" +
"<HTML>" +
"<HEAD><TITLE>404</TITLE></HEAD>" +
"<BODY>404 Not Found" +
"<br> nothing </BODY></HTML>" ;
Then, I have used PrintStream instace to send the message, its argument is message.getBytes()
然后,我使用PrintStream实例发送消息,其参数为
message.getBytes()
The html message is not seen on the browser. 在浏览器中看不到html消息。
PrintStream sender = new PrintStream(this.socket.getOutputStream());
String message = // above lines
sender.write(message.getBytes())
Assuming you are sending this data across via a raw socket, you need to fix the following: 假设您正在通过原始套接字发送此数据,则需要修复以下问题:
Content-type
should be Content-Type
, and there is no standard header named error
(unless thats a custom one your sending, remove it). Content-type
应该是Content-Type
,并且没有命名为error
标准头(除非那是您发送的自定义项,请将其删除)。 html
is not a valid content type, try text/html
. html
不是有效的内容类型,请尝试使用text/html
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.