/** * @param request * @return * @throws IOException * @throws HttpExecuteException * @throws MalformedURLException */ private HttpResponse executeRequest(HttpRequest request) throws IOException { if (request.shouldIgnoreResponse()) return new HttpResponse(); if (!request.hasHeader("Host")) throw new HttpExecuteException("HTTP Host not set"); String host = request.getHeader("Host").get(0); URL url = new URL("http", host, 80, request.getPath()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(request.getMethod()); for (Entry<String, List<String>> entry : request.getHeaderPairs().entrySet()) { for (String value : entry.getValue()) connection.addRequestProperty(entry.getKey(), value); } if (request.getMethod().equals("POST")) { // Write post data if it exists connection.getOutputStream().write(request.getContent()); } HttpResponse response = new HttpResponse(); response.setResponseCode(connection.getResponseCode()); response.setResponseMessage(connection.getResponseMessage()); for (Entry<String, List<String>> entry : connection.getHeaderFields().entrySet()) { for (String value : entry.getValue()) response.addHeader(entry.getKey(), value); } // responseType is eg. the 4 in 403 int responseType = response.getResponseCode() / 100; if (responseType == 4 || responseType == 5) response.readAllContent(connection.getErrorStream()); else response.readAllContent(connection.getInputStream()); // Add Network Spoofer fingerprint response.addHeader("X-Network-Spoofer", "ON"); return response; }