[英]Generate HTTP response in java proxy server
How would I display an HTTP 403 response to the client when the client attempts to access a forbidden page? 当客户端尝试访问禁止页面时,如何显示对客户端的HTTP 403响应? I have the code below, but it doesn't display anything on the clients browser.
我有以下代码,但在客户端浏览器上未显示任何内容。 May be a trivial error, but I'm new to this so anything helps.
可能是一个微不足道的错误,但是我对此并不陌生,所以任何帮助都可以。
// If webpage is not allowed, then redirect user to a blocked
// URL page
if (!checkHost(fin, requestSplit[3].split("\r")[0])) {
System.out.println("DON'T SHOW");
OutputStream to_client = clientSocket.getOutputStream();
PrintStream ps = new PrintStream(to_client);
ps.print("HTTP/1.1 403 Forbidden\r\n");
ps.print("Connection: close\r\n");
ps.print("\r\n");
ps.close();
PrintStream,
not the Socket.
PrintStream,
而不是Socket.
\\r\\n
, not whatever println()
does, which is platform-dependent. \\r\\n
,而与平台相关的println()
无关。 Content-type
, a Date
, or an Accept-Ranges
header in a 404 response. Content-type
, Date
或Accept-Ranges
标头没有意义。 incomingOS
is a terrible name for an output stream. incomingOS
是输出流的可怕名称。 Your edit doesn't comply with (2) above. 您的修改不符合上面的(2)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.