当前位置: 首页>>代码示例>>Java>>正文


Java ManagedClientConnection.sendRequestHeader方法代码示例

本文整理汇总了Java中org.apache.http.conn.ManagedClientConnection.sendRequestHeader方法的典型用法代码示例。如果您正苦于以下问题:Java ManagedClientConnection.sendRequestHeader方法的具体用法?Java ManagedClientConnection.sendRequestHeader怎么用?Java ManagedClientConnection.sendRequestHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.conn.ManagedClientConnection的用法示例。


在下文中一共展示了ManagedClientConnection.sendRequestHeader方法的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);
    }

}
 
开发者ID:mleoking,项目名称:PhET,代码行数:65,代码来源:ManagerConnectDirect.java


注:本文中的org.apache.http.conn.ManagedClientConnection.sendRequestHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。