第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在Java中使用HttpClient的HTTP基本身份驗證?

在Java中使用HttpClient的HTTP基本身份驗證?

SMILET 2019-07-19 15:42:47
在Java中使用HttpClient的HTTP基本身份驗證?我試圖在Java中模仿這個curl命令的功能:curl --basic --user username:password -d "" http://ipaddress/test/login我使用CommonsHttpClient3.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" + post.getResponseBodyAsString());             } finally {                 // release any connection resources used by the method                 post.releaseConnection();             }         } catch (Exception e) {             // TODO Auto-generated catch block             e.printStackTrace();         }     }    }
查看完整描述

3 回答

?
一只名叫tom的貓

TA貢獻1906條經驗 獲得超3個贊

您是否嘗試過(使用HttpClient版本4):


String encoding = Base64Encoder.encode(user + ":" + pwd);

HttpPost httpPost = new HttpPost("http://host:post/test/login");

httpPost.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + encoding);


System.out.println("executing request " + httpPost.getRequestLine());

HttpResponse response = httpClient.execute(httpPost);

HttpEntity entity = response.getEntity();


查看完整回答
反對 回復 2019-07-19
  • 3 回答
  • 0 關注
  • 1651 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號