⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicauthenticationdemo.java~1~

📁 这是用JAVA的SOCKET类实现的HTTP CLIENT的代码。通过它可以让原来很头疼的事情现在轻松的解决
💻 JAVA~1~
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -