Java Code Examples for com.sun.net.httpserver.HttpExchange.getResponseHeaders()
阿新 • • 發佈:2019-02-14
The following are Jave code examples for showing how to use getResponseHeaders()
of theclass.
You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Project: fourinone-master View
Source |
6 votes |
publicvoid handle(HttpExchange exchange)throwsIOException{/*InputStream is = t.getRequestBody(); String response = "response ok"; t.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); */Example 2Headers responseHeaders = exchange.getResponseHeaders(); responseHeaders.set("Content-Type","text/html");String response =ConfigContext.getRequest(ConfigContext.getProp("RSPE404")); exchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND, response.length());OutputStream os = exchange.getResponseBody(); os.write(response.getBytes()); os.close();}
Project: victims-lib-java-master View Source | 6 votes |
publicvoid handle(HttpExchange exchange){try{Headers headers = exchange.getResponseHeaders(); headers.add("Content-Type","application/json"); exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, json.length);OutputStream os = exchange.getResponseBody(); os.write(json); os.close();}catch(Exception e){ e.printStackTrace();}}Example 3
Project: Fourinone-master View Source | 6 votes |
publicvoid handle(HttpExchange exchange)throwsIOException{/*InputStream is = t.getRequestBody(); String response = "response ok"; t.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); */Headers responseHeaders = exchange.getResponseHeaders(); responseHeaders.set("Content-Type","text/html");String response =ConfigContext.getRequest(ConfigContext.getProp("RSPE404")); exchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND, response.length());OutputStream os = exchange.getResponseBody(); os.write(response.getBytes()); os.close();}Example 4
Project: mock-httpserver-master View Source | 6 votes |
privatevoid sendHeaders(HttpExchange httpExchange,Response response)throwsIOException{int length = response.getContent().getLength();int statusCode = response.getStatus().getStatusCode();Headers responseHeaders = httpExchange.getResponseHeaders();Header headers = response.getHeader();for(String headerField : headers.getHeaderFields()){for(Header.Parameter value : headers.getHeaderParameter(headerField)){ responseHeaders.add(headerField, value.toString());}} addHeaderIfSet(responseHeaders,Header.Fields.CONTENT_ENCODING, response.getContent().getEncoding()); addHeaderIfSet(responseHeaders,Header.Fields.CONTENT_LANGUAGE, response.getContent().getLanguage()); addHeaderIfSet(responseHeaders,Header.Fields.CONTENT_MD5, response.getContent().getMd5()); addHeaderIfSet(responseHeaders,Header.Fields.CONTENT_TYPE, response.getContent().getComposedContentType()); addHeaderIfSet(responseHeaders,Header.Fields.CONTENT_RANGE, response.getContent().getRange()); httpExchange.sendResponseHeaders(statusCode, max(0, length));}Example 5
Project: product-esb-master View Source | 6 votes |
publicvoid handle(HttpExchange t)throwsIOException{Headers h = t.getResponseHeaders(); h.add("Content-Type", contentType);String response ="This Content type test case"; t.sendResponseHeaders(200, response.length());OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close();}Example 6