HttpClient处理Basic认证CODE-创新互联
package com.favccxx.favsoft.main; import java.net.URI; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.RequestBuilder; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; public class CreditTest { public static void main(String[] args) throws Exception { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope("10.0.0.100", 8080), new UsernamePasswordCredentials("basicuser", "password")); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); HttpUriRequest login = RequestBuilder.post() .setUri(new URI( "http://10.0.0.100:8080/hibaby/getBabiesByGender")) .addParameter("appKey", "BEST") .addParameter("gender", "boy").build(); CloseableHttpResponse response = httpclient.execute(login); System.out.println("响应状态:" + response.getStatusLine()); String result = EntityUtils.toString(response.getEntity(), "UTF-8"); System.out.println("Result: " + result); } }让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:主机域名、网络空间、营销软件、网站建设、扎赉特网站维护、网站推广。
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站标题:HttpClient处理Basic认证CODE-创新互联
转载源于:http://lswzjz.com/article/ddihsj.html