public static int putUrlAsString(String content, String url) throws HTTPException { HTTPSession session = new HTTPSession(url); HTTPMethod m = HTTPMethod.Put(session); m.setRequestContentAsString(content); int status = m.execute(); m.close(); return status; }
static String getUrlAsString(String url) throws HTTPException { try (HTTPMethod m = HTTPFactory.Get(url); ) { int status = m.execute(); String content = null; if (status == 200) { content = m.getResponseAsString(); } return content; } }
public static String getUrlAsString(String url) throws HTTPException { HTTPSession session = new HTTPSession(url); HTTPMethod m = HTTPMethod.Get(session); int status = m.execute(); String content = null; if (status == 200) { content = m.getResponseAsString(); } m.close(); return content; }
static int putUrlAsString(String content, String url) throws HTTPException { int status = 0; try { try (HTTPMethod m = HTTPFactory.Put(url)) { m.setRequestContent( new StringEntity(content, ContentType.create("application/text", "UTF-8"))); status = m.execute(); } } catch (UnsupportedCharsetException uce) { throw new HTTPException(uce); } return status; }