basicauthenticationdemo.java~1~
来自「这是用JAVA的SOCKET类实现的HTTP CLIENT的代码。通过它可以让原」· JAVA~1~ 代码 · 共 31 行
JAVA~1~
31 行
package org.apache.commons.httpclient.demo;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;
public class BasicAuthenticationDemo {
public BasicAuthenticationDemo() {
}
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
client.getState().setCredentials(
"www.verisign.com",
"realm",
new UsernamePasswordCredentials("username", "password")
);
GetMethod get = new GetMethod("https://www.verisign.com/products/index.html");
get.setDoAuthentication(true);
int status = client.executeMethod(get);
System.out.println(status + "" + get.getResponseBodyAsString());
get.releaseConnection();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?