import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.HttpClient; import java.util.concurrent.TimeUnit; public class AsynchronousHttpClientExample { public static void main(String[] args) throws Exception { HttpClient httpClient = new HttpClient(); httpClient.start(); Request request = httpClient.newRequest("https://example.com/api/endpoint") .method(HttpMethod.GET) .timeout(5000, TimeUnit.MILLISECONDS); ContentResponse response = request.send(); System.out.println(response.getContentAsString()); httpClient.stop(); } } <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <Configure id="Server" class="org.eclipse.jetty.server.Server"> <Call name="addBean"> <Arg> <New class="org.eclipse.jetty.server.ServerConnector"> <Arg name="server"><Ref refid="Server" /></Arg> <Set name="port">8080</Set> </New> </Arg> </Call> <!-- Other configurations --> </Configure> import org.eclipse.jetty.xml.XmlConfiguration; // ... XmlConfiguration configuration = new XmlConfiguration(new File("jetty-config.xml").toURI().toURL()); configuration.configure(server);


上一篇:
下一篇:
切换中文