English 中文(简体)
Java HTTPAUTH
原标题:Java HTTP AUTH?
最佳回答

查阅网站:

所有文件/文件都需要https request和HTTP-Auth。

HTTP-Auth is header used in basic authentication.
In Java, you can simply put your credentials in the URL:

http://user:pass@www.example.com/

您可以核实,该编码是使用)方法正确确定的。

问题回答

如果你确实需要吉大港山区基本居住条件,你可以像现在这样形成:

http://user:password@www.website.com

最新资料:

利用所提供的实例,这项工作应当:

https://user:password@api.del.icio.us/v1/posts/add&url=http://www.google.com&description=awesome

答案是:

public String reloadTomcatWebApplication(String user, String pwd, String urlWithParameters, boolean returnResponse){        
    URL url = null;
    try {

        url = new URL(urlWithParameters);
    } catch (MalformedURLException e) {
        System.out.println("MalformedUrlException: " + e.getMessage());
        e.printStackTrace();
        return "-1";
    }

    URLConnection uc = null;
    try {
        uc = url.openConnection();
    } catch (IOException e) {
        System.out.println("IOException: " + e.getMessage());
        e.printStackTrace(); 
        return "-12";
    }


    String userpass = user + ":" + pwd;
    String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());

    uc.setRequestProperty ("Authorization", basicAuth);

    InputStream is = null;
    try {
        is = uc.getInputStream();
    } catch (IOException e) {
        System.out.println("IOException: " + e.getMessage());
        e.printStackTrace();
        return "-13";
    }
    if(returnResponse){
    BufferedReader buffReader = new BufferedReader(new InputStreamReader(is));
    StringBuffer response = new StringBuffer();

    String line = null;
    try {
        line = buffReader.readLine();
    } catch (IOException e) {
        e.printStackTrace();
        return "-1";
    }

    while (line != null) {
        response.append(line);
        response.append( 
 );
        try {
            line = buffReader.readLine();
        } catch (IOException e) {
            System.out.println(" IOException: " + e.getMessage());
            e.printStackTrace();
            return "-14";
        }
    }

    try {
        buffReader.close();
    } catch (IOException e) {
        e.printStackTrace();
        return "-15";
    }       
    System.out.println("Response: " + response.toString());
    return response.toString();

    }               
    return "0";
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签