private static void writeRequestHeaders ( OutputStream pOut , URL pURL , String pMethod , Properties pProps , boolean pUsingProxy , PasswordAuthentication pAuth , String pAuthType ) { PrintWriter out = new PrintWriter ( pOut , true ) ; // autoFlush if ( ! pUsingProxy ) { out . println ( pMethod + " " + ( ! StringUtil . isEmpty ( pURL . getPath ( ) ) ? pURL . getPath ( ) : "/" ) + ( ( pURL . getQuery ( ) != null ) ? "?" + pURL . getQuery ( ) : "" ) + " HTTP/1.1" ) ; // HTTP/1.1 // out.println("Connection: close"); // No persistent connections yet /* System.err.println(pMethod + " " + (!StringUtil.isEmpty(pURL.getPath()) ? pURL.getPath() : "/") + (pURL.getQuery() != null ? "?" + pURL.getQuery() : "") + " HTTP/1.1"); // HTTP/1.1 */ // Authority (Host: HTTP/1.1 field, but seems to work for HTTP/1.0) out . println ( "Host: " + pURL . getHost ( ) + ( ( pURL . getPort ( ) != - 1 ) ? ":" + pURL . getPort ( ) : "" ) ) ; /* System.err.println("Host: " + pURL.getHost() + (pURL.getPort() != -1 ? ":" + pURL.getPort() : "")); */ } else { ////-- PROXY (absolute) VERSION out . println ( pMethod + " " + pURL . getProtocol ( ) + "://" + pURL . getHost ( ) + ( ( pURL . getPort ( ) != - 1 ) ? ":" + pURL . getPort ( ) : "" ) + pURL . getPath ( ) + ( ( pURL . getQuery ( ) != null ) ? "?" + pURL . getQuery ( ) : "" ) + " HTTP/1.1" ) ; } // Check if we have authentication if ( pAuth != null ) { // If found, set Authorization header byte [ ] userPass = ( pAuth . getUserName ( ) + ":" + new String ( pAuth . getPassword ( ) ) ) . getBytes ( ) ; // "Authorization" ":" credentials out . println ( "Authorization: " + pAuthType + " " + BASE64 . encode ( userPass ) ) ; /* System.err.println("Authorization: " + pAuthType + " " + BASE64.encode(userPass)); */ } // Iterate over properties for ( Map . Entry < Object , Object > property : pProps . entrySet ( ) ) { out . println ( property . getKey ( ) + ": " + property . getValue ( ) ) ; //System.err.println(property.getKey() + ": " + property.getValue()); } out . println ( ) ; // Empty line, marks end of request-header }
Writes the HTTP request headers for HTTP GET method .