Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 向登录网站发送http post请求?(授权)_Java_Http_Login_Request_Authorization - Fatal编程技术网

Java 向登录网站发送http post请求?(授权)

Java 向登录网站发送http post请求?(授权),java,http,login,request,authorization,Java,Http,Login,Request,Authorization,我有两门课: public class ProtectedAuthorizer extends Authenticator { public String authorizeProtectedUrl(String requestingUrl) { Authenticator.setDefault(new CustomAuthenticator()); StringBuffer sb = null; try { URL url = new URL(r

我有两门课:

public class ProtectedAuthorizer extends Authenticator {

public String authorizeProtectedUrl(String requestingUrl) {

    Authenticator.setDefault(new CustomAuthenticator());

    StringBuffer sb = null;

    try {
        URL url = new URL(requestingUrl);
        BufferedReader br = new BufferedReader(new InputStreamReader(
                url.openStream()));

        String in = "";
        sb = new StringBuffer();

        while ((in = br.readLine()) != null) {
            sb.append(in + "\n");
        }
        br.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}
}
这是我的第二节课:

    protected PasswordAuthentication getPasswordAuthentication() {

    String username = "username";
    String password = "password";

    String promptString = getRequestingPrompt();
    String hostname = getRequestingHost();
    InetAddress ipaddr = getRequestingSite();
    int port = getRequestingPort();

    System.out.println(promptString);
    System.out.println(hostname);
    System.out.println(ipaddr);
    System.out.println(port);

    return new PasswordAuthentication(username, password.toCharArray());
}

}
我正在尝试授权自己访问此网站: 但每当我打电话

authorizeProtectedUrl("https://id.ogplanet.com/login.og"); 

它没有任何作用。如何使用这两个类来授权自己登录页面?(向登录页面发送HTTP Post请求)

对于与HTTP相关的内容,我建议使用该库。在项目网站上,有一些。看这张照片。在我看来,它与您的用例非常匹配。

您在哪里调用getPasswordAuthentication()?如果我想授权自己,这不是我应该调用的吗?