如何通过用户登录验证成功调用该API接口呢?
- 内容介绍
- 文章标签
- 相关推荐
本文共计114个文字,预计阅读时间需要1分钟。
javaimport HttpClient;import UsernamePasswordCredentials;import AuthScope;import GetMethod;
gistfile1.txtimport org.apache.commons.gerrit.ext.net.nokia.com/gerrit/a/accounts/?q=is:active"); // Tell the GET method to automatically handle authentication. The // method will use any appropriate credentials to handle basic // authentication requests. Setting this value to false will cause // any request for authentication to return with a status of 401. // It will then be up to the client to handle the authentication. get.setDoAuthentication(true); try { // execute the GET int status = client.executeMethod(get); // print the status and response System.out.println(status + "\n" + get.getResponseBodyAsString()); } finally { // release any connection resources used by the method get.releaseConnection(); } } }
本文共计114个文字,预计阅读时间需要1分钟。
javaimport HttpClient;import UsernamePasswordCredentials;import AuthScope;import GetMethod;
gistfile1.txtimport org.apache.commons.gerrit.ext.net.nokia.com/gerrit/a/accounts/?q=is:active"); // Tell the GET method to automatically handle authentication. The // method will use any appropriate credentials to handle basic // authentication requests. Setting this value to false will cause // any request for authentication to return with a status of 401. // It will then be up to the client to handle the authentication. get.setDoAuthentication(true); try { // execute the GET int status = client.executeMethod(get); // print the status and response System.out.println(status + "\n" + get.getResponseBodyAsString()); } finally { // release any connection resources used by the method get.releaseConnection(); } } }

