-
大小: 1.82MB文件類型: .rar金幣: 2下載: 0 次發布日期: 2023-10-25
- 語言: 其他
- 標簽: httpclient??
資源簡介
HttpClient,發送異步請求,get、post請求

代碼片段和文件信息
/*
?*?====================================================================
?*?Licensed?to?the?Apache?Software?Foundation?(ASF)?under?one
?*?or?more?contributor?license?agreements.??See?the?NOTICE?file
?*?distributed?with?this?work?for?additional?information
?*?regarding?copyright?ownership.??The?ASF?licenses?this?file
?*?to?you?under?the?Apache?License?Version?2.0?(the
?*?“License“);?you?may?not?use?this?file?except?in?compliance
?*?with?the?License.??You?may?obtain?a?copy?of?the?License?at
?*
?*???http://www.apache.org/licenses/LICENSE-2.0
?*
?*?Unless?required?by?applicable?law?or?agreed?to?in?writing
?*?software?distributed?under?the?License?is?distributed?on?an
?*?“AS?IS“?BASIS?WITHOUT?WARRANTIES?OR?CONDITIONS?OF?ANY
?*?KIND?either?express?or?implied.??See?the?License?for?the
?*?specific?language?governing?permissions?and?limitations
?*?under?the?License.
?*?====================================================================
?*
?*?This?software?consists?of?voluntary?contributions?made?by?many
?*?individuals?on?behalf?of?the?Apache?Software?Foundation.??For?more
?*?information?on?the?Apache?Software?Foundation?please?see
?*? .
?*
?*/
package?org.apache.http.examples.nio.client;
import?org.apache.http.HttpResponse;
import?org.apache.http.auth.AuthScope;
import?org.apache.http.auth.UsernamePasswordCredentials;
import?org.apache.http.client.CredentialsProvider;
import?org.apache.http.client.methods.HttpGet;
import?org.apache.http.impl.client.BasicCredentialsProvider;
import?org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import?org.apache.http.impl.nio.client.HttpAsyncClients;
import?java.util.concurrent.Future;
/**
?*?A?simple?example?that?uses?HttpClient?to?execute?an?HTTP?request?against
?*?a?target?site?that?requires?user?authentication.
?*/
public?class?AsyncClientAuthentication?{
????public?static?void?main(String[]?args)?throws?Exception?{
????????CredentialsProvider?credsProvider?=?new?BasicCredentialsProvider();
????????credsProvider.setCredentials(
????????????????new?AuthScope(“localhost“?443)
????????????????new?UsernamePasswordCredentials(“username“?“password“));
????????CloseableHttpAsyncClient?httpclient?=?HttpAsyncClients.custom()
????????????????.setDefaultCredentialsProvider(credsProvider)
????????????????.build();
????????try?{
????????????HttpGet?httpget?=?new?HttpGet(“http://localhost/“);
????????????System.out.println(“Executing?request?“?+?httpget.getRequestLine());
????????????Future?future?=?httpclient.execute(httpget?null);
????????????HttpResponse?response?=?future.get();
????????????System.out.println(“Response:?“?+?response.getStatusLine());
????????????System.out.println(“Shutting?down“);
????????}?finally?{
????????????httpclient.close();
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????380??2016-07-11?11:51??http_client\.classpath
?????文件????????387??2016-07-11?11:42??http_client\.project
?????文件?????????79??2016-07-11?12:12??http_client\.settings\org.eclipse.core.resources.prefs
?????文件????????598??2016-07-11?11:42??http_client\.settings\org.eclipse.jdt.core.prefs
?????文件???????2995??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientAuthentication.class
?????文件???????1394??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientConfiguration$1$1.class
?????文件???????1740??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientConfiguration$1.class
?????文件???????1029??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientConfiguration$2.class
?????文件??????11793??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientConfiguration.class
?????文件???????3032??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientCustomContext.class
?????文件???????3851??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientCustomSSL.class
?????文件???????2201??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientEvictExpiredConnections$1.class
?????文件???????1541??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientEvictExpiredConnections$IdleConnectionEvictor.class
?????文件???????3278??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientEvictExpiredConnections.class
?????文件???????2769??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientExecuteProxy.class
?????文件???????2065??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientHttpExchange.class
?????文件???????2213??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientHttpExchangeFutureCallback$1.class
?????文件???????2912??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientHttpExchangeFutureCallback.class
?????文件???????1873??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientHttpExchangeStreaming$MyResponseConsumer.class
?????文件???????2212??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientHttpExchangeStreaming.class
?????文件???????3591??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\AsyncClientProxyAuthentication.class
?????文件???????2108??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\QuickStart$1.class
?????文件???????1539??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\QuickStart$2.class
?????文件???????2108??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\QuickStart$3.class
?????文件???????3389??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\QuickStart.class
?????文件???????1765??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\ZeroCopyHttpExchange$1.class
?????文件???????2653??2016-07-11?11:51??http_client\bin\org\apache\http\examples\nio\client\ZeroCopyHttpExchange.class
?????文件?????232771??2016-07-11?11:44??http_client\lib\commons-codec-1.6.jar
?????文件?????279781??2016-07-11?12:32??http_client\lib\commons-httpclient-3.0.1.jar
?????文件??????62050??2016-07-11?11:44??http_client\lib\commons-logging-1.1.3.jar
............此處省略42個文件信息
評論
共有 條評論