时间:2021-07-01 10:21:17 帮助过:11人阅读
// create FastCGI connection FCGIConnection connection = FCGIConnection.open();connection.connect( new InetSocketAddress( " 127.0.0.1 " , 9000 ));connection.beginRequest( " fcgi.php " ); // set the HTTP METHOD,GET for default connection.setRequestMethod( " post " ); // set the queryString, not required when no queryString connection.setQueryString( " text=hello " ); // add FCGIParams connection.addParams( " DOCUMENT_ROOT " , " /var/www " ); byte [] postData = " hello=world " .getBytes(); // set contentLength, it's importent connection.setContentLength(postData.length);connection.write(ByteBuffer.wrap(postData)); // print response headers Map < String, String > responseHeaders = connection.getResponseHeaders(); for (String key : responseHeaders.keySet()){ System.out.println( " HTTP HEADER: " + key + " -> " + responseHeaders.get(key));} // read response data ByteBuffer buffer = ByteBuffer.allocate( 10240 );connection.read(buffer);buffer.flip(); byte [] data = new byte [buffer.remaining()];buffer.get(data);System.out.println( new String(data)); // close the connection connection.close();