2017-06-12 15 views
-3

以下のレストサービス用のレストクライアントの作成にお役立てください。Java rest webservice client

エンドポイントURL:http://xxxyyy.com

ヘッダー:コンテンツタイプ:アプリケーション/ x-www-form-urlencodedで;のcharset = UTF-8

ヘッダー:承認:基本:Base64encodedユーザー名とパスワード

本文:grant_type =パスワード&ユーザ名= xxx &パスワード= yyy

あなたのお手伝いがあります。

+0

あなたのコード全体を記述しますか? – Akshay

+1

まず自分自身を試してみましょう。障害のある方は – FieryCat

+0

私のアプローチは投稿しました –

答えて

-1

私は以下のようにしましたが、2番目のヘッダーと本文をどこに追加するのか分かりません。

String url = "http://xxx"; 
    String name = "xxx"; 
    String password = "yyy"; 
    String authString = name + ":" + password; 
    String authStringEnc = new BASE64Encoder().encode(authString.getBytes()); 
    System.out.println("Base64 encoded auth string: " + authStringEnc); 
    Client restClient = Client.create(); 
    WebResource webResource = restClient.resource(url); 
    ClientResponse resp = webResource.accep`enter code here`t("application/json") 
            .header("Authorization", "Basic " + authStringEnc) 
            .get(ClientResponse.class); 





    if(resp.getStatus() != 200){ 
     System.err.println("Unable to connect to the server"); 
    } 
    String output = resp.getEntity(String.class); 
    System.out.println("response: "+output); 
+0

'Client'、' WebSource'、 'ClientResponse'とは​​何ですか? –

関連する問題