List of usage examples for org.apache.commons.httpclient.methods EntityEnclosingMethod CONTENT_LENGTH_AUTO
long CONTENT_LENGTH_AUTO
To view the source code for org.apache.commons.httpclient.methods EntityEnclosingMethod CONTENT_LENGTH_AUTO.
Click Source Link
From source file:com.krawler.esp.utils.HttpPost.java
public String invoke(String soapMessage) { try {//from www .j a v a2 s.c o m int statusCode = -1; String mUri = "http://localhost:7070/service/soap/"; // the content-type charset will determine encoding used // when we set the request body PostMethod method = new PostMethod(mUri); // method.setRequestHeader("Content-type", // getSoapProtocol().getContentType()); method.setRequestBody(soapMessage); method.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_AUTO); // if (getSoapProtocol().hasSOAPActionHeader()) // method.setRequestHeader("SOAPAction", mUri); // execute the method. HttpClient mClient = new HttpClient(); statusCode = mClient.executeMethod(method); // Read the response body. byte[] responseBody = method.getResponseBody(); // Release the connection. method.releaseConnection(); // Deal with the response. // Use caution: ensure correct character encoding and is not binary // data String responseStr = toString(responseBody); return responseStr; } catch (IOException ex) { return ex.toString(); } catch (Exception ex) { return ex.toString(); } }
From source file:de.lohndirekt.print.IppHttpConnection.java
/** * @param uri/* ww w . j av a 2s.c o m*/ * @param user * @param passwd * @param useStream */ public IppHttpConnection(URI uri, String user, String passwd) { try { httpConn = new HttpClient(); method = new PostMethod(toHttpURI(uri).toString()); method.addRequestHeader("Content-type", "application/ipp"); method.addRequestHeader("Accept", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"); method.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_AUTO); // authentication if (user != null && user.trim().length() > 0) { if (log.isLoggable(Level.FINER)) { log.log(Level.SEVERE, "Using username: " + user + " , passwd.length " + passwd.length()); } method.setDoAuthentication(true); Credentials creds = new UsernamePasswordCredentials(user, passwd); httpConn.getState().setCredentials(null, toHttpURI(uri).getHost(), creds); } } catch (Exception e) { log.log(Level.SEVERE, e.getMessage(), e); } }