我试图模仿Java中这个curl命令的功能:
curl --basic --user username:password -d "" http://ipaddress/test/login
Run Code Online (Sandbox Code Playgroud)
我使用Commons HttpClient 3.0编写了以下内容但不知何故最终500 Internal Server Error从服务器获取了一个.有人能告诉我,如果我做错了吗?
public class HttpBasicAuth {
private static final String ENCODING = "UTF-8";
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope("ipaddress", 443, "realm"),
new UsernamePasswordCredentials("test1", "test1")
);
PostMethod post = new PostMethod(
"http://address/test/login");
post.setDoAuthentication( true );
try {
int status = client.executeMethod( post );
System.out.println(status + "\n" + …Run Code Online (Sandbox Code Playgroud)