List of usage examples for org.apache.commons.httpclient HttpClient HttpClient
public HttpClient()
From source file:name.chengchao.myhttpclient.version3_1.HttpClient3Util.java
/** * ?url?ResponseBody,method=get//from www . j a va 2s . com * * @param url exp:http://192.168.1.1:8080/dir/target.html * @return byte[]? */ public static byte[] getDataFromUrl(String url, int timeout) { if (StringUtils.isBlank(url)) { logger.error("url is blank!"); return null; } HttpClient httpClient = new HttpClient(); // httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(8000); // ? httpClient.getParams().setSoTimeout(timeout); GetMethod method = new GetMethod(url); // fix??? method.setRequestHeader("Connection", "close"); // ??1 method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, false)); try { int statusCode = httpClient.executeMethod(method); if (statusCode == HttpStatus.SC_OK) { return method.getResponseBody(); } else { throw new RuntimeException("http request error,return code:" + statusCode + ",msg:" + new String(method.getResponseBody())); } } catch (HttpException e) { method.abort(); logger.error(e.getMessage()); } catch (IOException e) { method.abort(); logger.error(e.getMessage()); } finally { // Release the connection. method.releaseConnection(); } return null; }
From source file:javaapplicationclientrest.ControllerCliente.java
public ControllerCliente() { this.http = new HttpClient(); }
From source file:net.sf.antcontrib.net.httpclient.HttpClientType.java
public HttpClientType(Project p) { super(); setProject(p); client = new HttpClient(); }
From source file:name.chengchao.myhttpclient.version3_1.HttpClient3UtilError.java
/** * ?url?ResponseBody,method=get//from www . j ava 2 s.c o m * * @param url exp:http://192.168.1.1:8080/dir/target.html * @return byte[]? */ public static byte[] getDataFromUrl(String url, int timeout) { if (StringUtils.isBlank(url)) { logger.error("url is blank!"); return null; } HttpClient httpClient = new HttpClient(); // httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(8000); // ? httpClient.getParams().setSoTimeout(timeout); GetMethod method = new GetMethod(url); // fix??? // method.setRequestHeader("Connection", "close"); // ??1 method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, false)); try { int statusCode = httpClient.executeMethod(method); if (statusCode == HttpStatus.SC_OK) { return method.getResponseBody(); } else { throw new RuntimeException("http request error,return code:" + statusCode + ",msg:" + new String(method.getResponseBody())); } } catch (HttpException e) { method.abort(); logger.error(e.getMessage()); } catch (IOException e) { method.abort(); logger.error(e.getMessage()); } finally { // Release the connection. method.releaseConnection(); } return null; }
From source file:es.carebear.rightmanagement.client.admin.CreateGroup.java
public CreateGroup(String baseUri) { this.baseUri = baseUri; this.httpClient = new HttpClient(); }
From source file:es.carebear.rightmanagement.client.user.RegisterUser.java
public RegisterUser(String baseUri) { this.baseUri = baseUri; this.httpClient = new HttpClient(); }
From source file:es.carebear.rightmanagement.client.user.AddAllowedUserId.java
public AddAllowedUserId(String baseUri) { this.baseUri = baseUri; this.httpClient = new HttpClient(); }
From source file:net.jadler.AbstractJadlerStubbingResponseHeadersTest.java
@Before public void setUp() { this.client = new HttpClient(); initJadlerUsing(this.createServer()); }
From source file:com.markwatson.linkeddata.DBpediaLookupClient.java
public DBpediaLookupClient(String query) throws Exception { this.query = query; HttpClient client = new HttpClient(); String query2 = query.replaceAll(" ", "+"); HttpMethod method = new GetMethod( "http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=" + query2); try {/*w w w . j a va 2 s .co m*/ client.executeMethod(method); InputStream ins = method.getResponseBodyAsStream(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser sax = factory.newSAXParser(); sax.parse(ins, this); } catch (HttpException he) { System.err.println("Http error connecting to lookup.dbpedia.org"); } catch (IOException ioe) { System.err.println("Unable to connect to lookup.dbpedia.org"); } method.releaseConnection(); }
From source file:net.morphbank.mbsvc3.test.postImageFile.java
private boolean postImageFileTest() { boolean result = false; try {/*from w w w. j av a 2 s . co m*/ Object morphBankImageId; PostMethod post = null;// MorphBankTest.getImagePostRequest(morphBankImageId.toString(), // getImageFileName()); HttpClient httpclient = new HttpClient(); int postStatus = httpclient.executeMethod(post); System.out.println(post.getResponseBody()); if (postStatus == 200) { result = true; } } catch (Exception ex) { Exception killer = ex; } if (!result) { Object statusText = ""; } return result; }