HTTP 서버에서 Mac OS, Linux 인쇄 요청을 처리할 수 없음
서버 = HttpServer.create(new InetSocketAddress(포트), 0);
server.createContext(경로, 새로운 IppHandler());
서버.setExecutor(null);
서버.스타트();
}
개인 클래스 IppHandler는 HttpHandler를 구현합니다. {
@Override
public void handle(HttpExchange exchange) throws IOException {
Headers requestHeaders = exchange.getRequestHeaders();
//User-agent
String useragent = requestHeaders.getFirst("User-agent");
// int contentLength = Integer.parseInt(requestHeaders.getFirst("Content-length"));
//System.out.println("contentLength :" + contentLength);
if (exchange.getRequestMethod().equalsIgnoreCase("POST")) {
try {
OutputStream os = exchange.getResponseBody();
Map parameters =(Map)exchange.getAttribute("parameters");
System.out.println("parameters"+parameters);
InputStream is = exchange.getRequestBody();
System.out.println("++++++++++++++++++++++++++++++++++++++++");
byte[] inputstreamdata=is.readAllBytes();
System.out.println("inputstreamdata "+inputstreamdata.length+" bytes");
//Writing utf8 in file
File file = new File("C:\\Users\\admin\\Desktop\\mydoc.txt");
OutputStreamWriter datafile = new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8");
BufferedWriter buffwriter = new BufferedWriter(datafile);// Writing the data with
if(inputstreamdata.length>0) {
for (int i=0;i<inputstreamdata.length;i++)
{
byte mybyte=inputstreamdata[i];
// System.out.println("byte to binary"+Integer.toBinaryString(mybyte)); // 1111 1110
String resultWithPadZero = String.format("%12s", Integer.toBinaryString(mybyte)).replace(" ", "0");
//String resultWithPadZero = String.format(Integer.toBinaryString(mybyte));
//System.out.println(resultWithPadZero); // 00000000000000000000000011111110
// System.out.println(printBinary(resultWithPadZero, 8, "|"));
//Writing utf8 data in file
buffwriter.write(inputstreamdata[i]);
buffwriter.flush();
//System.out.println(inputstreamdata[i]);
}
System.out.println("POSTMETHOD***data written successfully");
buffwriter.close();
// String response = "Invalid shutdown key\n";
//exchange.sendResponseHeaders(HTTP_OK, response.getBytes().length);
//exchange.getResponseBody().write(response.getBytes());
byte test = (byte) 0x012;
//exchange.sendResponseHeaders(test, 0);// Idle - Invalid printer command "Clean".
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0);
System.out.println("after sendResponseHeaders response code is : "+exchange.getResponseCode());
}
} catch (NumberFormatException | IOException e) {
}
}
}
}
Reference
이 문제에 관하여(HTTP 서버에서 Mac OS, Linux 인쇄 요청을 처리할 수 없음), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/narendraomshiv/http-server-unable-to-handle-mac-os-linux-print-request-53d6텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)