本文整理汇总了Java中org.apache.http.conn.ManagedClientConnection.open方法的典型用法代码示例。如果您正苦于以下问题:Java ManagedClientConnection.open方法的具体用法?Java ManagedClientConnection.open怎么用?Java ManagedClientConnection.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.conn.ManagedClientConnection
的用法示例。
在下文中一共展示了ManagedClientConnection.open方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.http.conn.ManagedClientConnection; //导入方法依赖的package包/类
/**
* Main entry point to this example.
*
* @param args ignored
*/
public final static void main(String[] args)
throws Exception {
final HttpHost target = new HttpHost("jakarta.apache.org", 80, "http");
setup(); // some general setup
ClientConnectionManager clcm = createManager();
HttpRequest req = createRequest(target);
HttpContext ctx = createContext();
System.out.println("preparing route to " + target);
HttpRoute route = new HttpRoute
(target, null, supportedSchemes.getScheme(target).isLayered());
System.out.println("requesting connection for " + route);
ClientConnectionRequest connRequest = clcm.requestConnection(route, null);
ManagedClientConnection conn = connRequest.getConnection(0, null);
try {
System.out.println("opening connection");
conn.open(route, ctx, getParams());
System.out.println("sending request");
conn.sendRequestHeader(req);
// there is no request entity
conn.flush();
System.out.println("receiving response header");
HttpResponse rsp = conn.receiveResponseHeader();
System.out.println("----------------------------------------");
System.out.println(rsp.getStatusLine());
Header[] headers = rsp.getAllHeaders();
for (int i=0; i<headers.length; i++) {
System.out.println(headers[i]);
}
System.out.println("----------------------------------------");
System.out.println("closing connection");
conn.close();
} finally {
if (conn.isOpen()) {
System.out.println("shutting down connection");
try {
conn.shutdown();
} catch (Exception x) {
System.out.println("problem during shutdown");
x.printStackTrace(System.out);
}
}
System.out.println("releasing connection");
clcm.releaseConnection(conn, -1, null);
}
}