public static String requestUrl ( final String url , final String method , final Properties header , final String body ) { try { final URL siteUrl = new URL ( url ) ; final HttpURLConnection connection = ( HttpURLConnection ) siteUrl . openConnection ( ) ; connection . setRequestMethod ( method ) ; final Enumeration < ? > keys = header . keys ( ) ; while ( keys . hasMoreElements ( ) ) { final String key = ( String ) keys . nextElement ( ) ; connection . addRequestProperty ( key , header . getProperty ( key ) ) ; } connection . setDoOutput ( true ) ; final OutputStream out = connection . getOutputStream ( ) ; out . write ( body . getBytes ( ) ) ; connection . connect ( ) ; final int errorCode = connection . getResponseCode ( ) ; if ( errorCode != HttpURLConnection . HTTP_OK ) { throw new JKHttpException ( connection . getResponseMessage ( ) , errorCode ) ; } final String response = JKIOUtil . convertToString ( connection . getInputStream ( ) ) ; return response ; } catch ( IOException e ) { throw new JKHttpException ( e ) ; } }
Send http request .