List of usage examples for org.apache.http.message BasicHttpRequest BasicHttpRequest
public BasicHttpRequest(String str, String str2, ProtocolVersion protocolVersion)
From source file:com.dlmu.heipacker.crawler.examples.conn.OperatorConnectDirect.java
public static void main(String[] args) throws Exception { HttpHost target = new HttpHost("jakarta.apache.org", 80, "http"); // some general setup // Register the "http" protocol scheme, it is required // by the default operator to look up socket factories. SchemeRegistry supportedSchemes = new SchemeRegistry(); supportedSchemes.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); // Prepare parameters. // Since this example doesn't use the full core framework, // only few parameters are actually required. HttpParams params = new SyncBasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(params, false); // one operator can be used for many connections ClientConnectionOperator scop = new DefaultClientConnectionOperator(supportedSchemes); HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1); req.addHeader("Host", target.getHostName()); HttpContext ctx = new BasicHttpContext(); OperatedClientConnection conn = scop.createConnection(); try {/* w w w . j av a 2 s .c o m*/ System.out.println("opening connection to " + target); scop.openConnection(conn, target, null, ctx, params); 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("----------------------------------------"); } finally { System.out.println("closing connection"); conn.close(); } }
From source file:httpclient.conn.OperatorConnectDirect.java
public static void main(String[] args) throws Exception { HttpHost target = new HttpHost("jakarta.apache.org", 80, "http"); // some general setup // Register the "http" protocol scheme, it is required // by the default operator to look up socket factories. SchemeRegistry supportedSchemes = new SchemeRegistry(); SocketFactory sf = PlainSocketFactory.getSocketFactory(); supportedSchemes.register(new Scheme("http", sf, 80)); // Prepare parameters. // Since this example doesn't use the full core framework, // only few parameters are actually required. HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(params, false); // one operator can be used for many connections ClientConnectionOperator scop = new DefaultClientConnectionOperator(supportedSchemes); HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1); req.addHeader("Host", target.getHostName()); HttpContext ctx = new BasicHttpContext(); OperatedClientConnection conn = scop.createConnection(); try {//from w ww .ja v a2 s. co m System.out.println("opening connection to " + target); scop.openConnection(conn, target, null, ctx, params); 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("----------------------------------------"); } finally { System.out.println("closing connection"); conn.close(); } }
From source file:httpclient.conn.OperatorConnectProxy.java
public static void main(String[] args) throws Exception { // make sure to use a proxy that supports CONNECT HttpHost target = new HttpHost("issues.apache.org", 443, "https"); HttpHost proxy = new HttpHost("127.0.0.1", 8666, "http"); // some general setup // Register the "http" and "https" protocol schemes, they are // required by the default operator to look up socket factories. SchemeRegistry supportedSchemes = new SchemeRegistry(); supportedSchemes.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); // Prepare parameters. // Since this example doesn't use the full core framework, // only few parameters are actually required. HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(params, false); // one operator can be used for many connections ClientConnectionOperator scop = new DefaultClientConnectionOperator(supportedSchemes); HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1); // In a real application, request interceptors should be used // to add the required headers. req.addHeader("Host", target.getHostName()); HttpContext ctx = new BasicHttpContext(); OperatedClientConnection conn = scop.createConnection(); try {//from w w w . jav a2 s .c om System.out.println("opening connection to " + proxy); scop.openConnection(conn, proxy, null, ctx, params); // Creates a request to tunnel a connection. // For details see RFC 2817, section 5.2 String authority = target.getHostName() + ":" + target.getPort(); HttpRequest connect = new BasicHttpRequest("CONNECT", authority, HttpVersion.HTTP_1_1); // In a real application, request interceptors should be used // to add the required headers. connect.addHeader("Host", authority); System.out.println("opening tunnel to " + target); conn.sendRequestHeader(connect); // there is no request entity conn.flush(); System.out.println("receiving confirmation for tunnel"); HttpResponse connected = conn.receiveResponseHeader(); System.out.println("----------------------------------------"); printResponseHeader(connected); System.out.println("----------------------------------------"); int status = connected.getStatusLine().getStatusCode(); if ((status < 200) || (status > 299)) { System.out.println("unexpected status code " + status); System.exit(1); } System.out.println("receiving response body (ignored)"); conn.receiveResponseEntity(connected); // Now we have a tunnel to the target. As we will be creating a // layered TLS/SSL socket immediately afterwards, updating the // connection with the new target is optional - but good style. // The scheme part of the target is already "https", though the // connection is not yet switched to the TLS/SSL protocol. conn.update(null, target, false, params); System.out.println("layering secure connection"); scop.updateSecureConnection(conn, target, ctx, params); // finally we have the secure connection and can send the request 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("----------------------------------------"); printResponseHeader(rsp); System.out.println("----------------------------------------"); } finally { System.out.println("closing connection"); conn.close(); } }
From source file:com.dlmu.heipacker.crawler.examples.conn.OperatorConnectProxy.java
public static void main(String[] args) throws Exception { // make sure to use a proxy that supports CONNECT HttpHost target = new HttpHost("issues.apache.org", 443, "https"); HttpHost proxy = new HttpHost("127.0.0.1", 8666, "http"); // some general setup // Register the "http" and "https" protocol schemes, they are // required by the default operator to look up socket factories. SchemeRegistry supportedSchemes = new SchemeRegistry(); supportedSchemes.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); supportedSchemes.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); // Prepare parameters. // Since this example doesn't use the full core framework, // only few parameters are actually required. HttpParams params = new SyncBasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(params, false); // one operator can be used for many connections ClientConnectionOperator scop = new DefaultClientConnectionOperator(supportedSchemes); HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1); // In a real application, request interceptors should be used // to add the required headers. req.addHeader("Host", target.getHostName()); HttpContext ctx = new BasicHttpContext(); OperatedClientConnection conn = scop.createConnection(); try {// w ww . j a va 2 s . com System.out.println("opening connection to " + proxy); scop.openConnection(conn, proxy, null, ctx, params); // Creates a request to tunnel a connection. // For details see RFC 2817, section 5.2 String authority = target.getHostName() + ":" + target.getPort(); HttpRequest connect = new BasicHttpRequest("CONNECT", authority, HttpVersion.HTTP_1_1); // In a real application, request interceptors should be used // to add the required headers. connect.addHeader("Host", authority); System.out.println("opening tunnel to " + target); conn.sendRequestHeader(connect); // there is no request entity conn.flush(); System.out.println("receiving confirmation for tunnel"); HttpResponse connected = conn.receiveResponseHeader(); System.out.println("----------------------------------------"); printResponseHeader(connected); System.out.println("----------------------------------------"); int status = connected.getStatusLine().getStatusCode(); if ((status < 200) || (status > 299)) { System.out.println("unexpected status code " + status); System.exit(1); } System.out.println("receiving response body (ignored)"); conn.receiveResponseEntity(connected); // Now we have a tunnel to the target. As we will be creating a // layered TLS/SSL socket immediately afterwards, updating the // connection with the new target is optional - but good style. // The scheme part of the target is already "https", though the // connection is not yet switched to the TLS/SSL protocol. conn.update(null, target, false, params); System.out.println("layering secure connection"); scop.updateSecureConnection(conn, target, ctx, params); // finally we have the secure connection and can send the request 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("----------------------------------------"); printResponseHeader(rsp); System.out.println("----------------------------------------"); } finally { System.out.println("closing connection"); conn.close(); } }
From source file:org.siddhiesb.transport.http.conn.ProxyTunnelHandler.java
public HttpRequest generateRequest(final HttpContext context) throws IOException, HttpException { HttpHost target = this.route.getTargetHost(); HttpRequest connect = new BasicHttpRequest("CONNECT", target.toHostString(), HttpVersion.HTTP_1_1); this.httpProcessor.process(connect, context); return connect; }
From source file:com.couchbase.client.TestingClient.java
public HttpFuture<String> asyncHttpGet(String uri) throws UnsupportedEncodingException { final CountDownLatch couchLatch = new CountDownLatch(1); final HttpFuture<String> crv = new HttpFuture<String>(couchLatch, operationTimeout); HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1); HttpOperationImpl op = new TestOperationImpl(request, new TestCallback() { private String json; @Override/*from w w w . ja v a 2s. co m*/ public void receivedStatus(OperationStatus status) { crv.set(json, status); } @Override public void complete() { couchLatch.countDown(); } @Override public void getData(String response) { json = response; } }); crv.setOperation(op); addOp(op); return crv; }
From source file:com.couchbase.client.ViewNodeTest.java
private HttpOperation createHttpOperation() { View view = new View("a", "b", "c", true, true); final CountDownLatch couchLatch = new CountDownLatch(1); final HttpFuture<ViewResponse> crv = new HttpFuture<ViewResponse>(couchLatch, 60000); final HttpRequest request = new BasicHttpRequest("GET", "/pools", HttpVersion.HTTP_1_1); return new NoDocsOperationImpl(request, view, new ViewOperation.ViewCallback() { private ViewResponse vr = null; @Override/*from w w w . ja va 2 s . c om*/ public void receivedStatus(OperationStatus status) { crv.set(vr, status); } @Override public void complete() { couchLatch.countDown(); } @Override public void gotData(ViewResponse response) { vr = response; } }); }
From source file:com.couchbase.client.TestingClient.java
public HttpFuture<String> asyncHttpDelete(String uri) throws UnsupportedEncodingException { final CountDownLatch couchLatch = new CountDownLatch(1); final HttpFuture<String> crv = new HttpFuture<String>(couchLatch, operationTimeout); HttpRequest request = new BasicHttpRequest("DELETE", uri, HttpVersion.HTTP_1_1); HttpOperationImpl op = new TestOperationImpl(request, new TestCallback() { private String json; @Override/*from w w w. j a v a2s .com*/ public void receivedStatus(OperationStatus status) { crv.set(json, status); } @Override public void complete() { couchLatch.countDown(); } @Override public void getData(String response) { json = response; } }); crv.setOperation(op); addOp(op); return crv; }
From source file:httpclient.conn.ManagerConnectDirect.java
/** * Creates a request to execute in this example. * In a real application, request interceptors should be used * to add the required headers./*from www. j a v a 2 s. c o m*/ * * @param target the target server for the request * * @return a request without an entity */ private final static HttpRequest createRequest(HttpHost target) { HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1); req.addHeader("Host", target.getHostName()); return req; }
From source file:fm.last.android.player.StreamProxy.java
private HttpRequest readRequest(Socket client) { HttpRequest request = null;/* ww w .j a v a 2s . c o m*/ InputStream is; String firstLine; String range = null; String ua = null; try { is = client.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is), 8192); firstLine = reader.readLine(); String line = null; do { line = reader.readLine(); if (line != null && line.toLowerCase().startsWith("range: ")) { range = line.substring(7); } if (line != null && line.toLowerCase().startsWith("user-agent: ")) { ua = line.substring(12); } } while (line != null && !"".equals(line) && reader.ready()); } catch (IOException e) { Log.e(LOG_TAG, "Error parsing request", e); return request; } if (firstLine == null) { Log.i(LOG_TAG, "Proxy client closed connection without a request."); return request; } StringTokenizer st = new StringTokenizer(firstLine); String method = st.nextToken(); String uri = st.nextToken(); Log.d(LOG_TAG, uri); String realUri = uri.substring(1); Log.d(LOG_TAG, realUri); request = new BasicHttpRequest(method, realUri, new ProtocolVersion("HTTP", 1, 1)); if (range != null) request.addHeader("Range", range); if (ua != null) request.addHeader("User-Agent", ua); return request; }