public static int putContent ( String urlencoded , String content ) throws IOException { try ( HTTPMethod m = HTTPFactory . Put ( urlencoded ) ) { m . setRequestContent ( new StringEntity ( content , "application/text" , "UTF-8" ) ) ; m . execute ( ) ; int resultCode = m . getStatusCode ( ) ; // followRedirect wont work for PUT if ( resultCode == 302 ) { String redirectLocation ; Header locationHeader = m . getResponseHeader ( "location" ) ; if ( locationHeader != null ) { redirectLocation = locationHeader . getValue ( ) ; resultCode = putContent ( redirectLocation , content ) ; } } return resultCode ; } }
Put content to a url using HTTP PUT . Handles one level of 302 redirection .