2016-11-14 16 views
1

xml-rpc POSTリクエストを作成し、2つのパラメータ "application_name" & "key"を渡してコンテンツタイプを "application/x-www-form-urlencoded "のようなものです。
Android:カスタムhttpヘッダーとコンテンツタイプで投稿xml-rpcリクエストを作成する方法

try { 
     XMLRPCClient oneTimeKeyClient = new XMLRPCClient(new URL(URL_REQUEST_SAMPLE), XMLRPCClient.FLAGS_DEFAULT_TYPE_STRING); 
     oneTimeKeyClient.setCustomHttpHeader("X-HTTP-METHOD-OVERRIDE", "POST"); 

// oneTimeKeyClient.setCustomHttpHeader( "のContent-Type"、 "アプリケーション/ x-www-form-urlencodedで")。

 HashMap<String, String> oneTimeKeyParam = new HashMap<>(); 
     oneTimeKeyParam.put("application_name", "hello_app"); 
     oneTimeKeyParam.put("key", "bb5eb953d3b41dcf59f4669d98f8e14782ed83133be772956b"); 
     Vector<Object> params = new Vector<Object>(); 
     params.add(oneTimeKeyParam); 

     oneTimeKeyClient.callAsync(new XMLRPCCallback() { 
      @Override 
      public void onResponse(long id, Object response) { 
       try { 
        result = ((Map) response).get(NAME_ONE_TIME_KEY).toString(); 
       } catch (Exception e) { 
        Timber.e("onParseError %s", e.getMessage()); 
        DialogUtil.showLoginErrorDialog(getSupportFragmentManager()); 
       } 
      } 

      @Override 
      public void onError(long id, XMLRPCException error) { 
       Timber.e("onError %s", error.getMessage()); 
       DialogUtil.showLoginErrorDialog(getSupportFragmentManager()); 
      } 

      @Override 
      public void onServerError(long id, XMLRPCServerException error) { 
       Timber.e("onServerError %s", error.getMessage()); 
       DialogUtil.showLoginErrorDialog(getSupportFragmentManager()); 
      } 
     }, "", params); 
    } catch (Exception e) { 
     Timber.e("onError %s", e.getMessage()); 
     DialogUtil.showLoginErrorDialog(getSupportFragmentManager()); 
    } 

エラーが発生しました。「onServerError APPLICATION_NAMEにはレコードが存在しません」というエラーが表示されます。
私はaXMLRPCライブラリhttps://github.com/gturri/aXMLRPCを使用しています。
どのライブラリをお勧めしますか?
Retrofitを使用してxml-rpcリクエストを行うことはできますか?

@FormUrlEncoded 
@POST("onetime_key") 
Observable<OneTimeKeyRes> requestOneTimeKey(@Field("application_name") String applicationName, @Field("key") String key); 

あなたはSimpleXmlConverterを追加する必要があります:あなたはちょうどこのように改造を使用する任意のヘルプ

答えて

2

ため
おかげ

Retrofit retrofit = new Retrofit.Builder() 
      .client(builder.build()) 
      .baseUrl(YOUR_BASE_URL) 
      .addConverterFactory(SimpleXmlConverterFactory.create()) 
      .build(); 
関連する問題