1

I want to creat xml-rpc POST request, and pass 2 parameters "application_name" & "key", and change content type to "application/x-www-form-urlencoded" like my code below.

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", "application/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());
    }

I got error " onServerError APPLICATION_NAME must record not exists."
I using aXMLRPC library https://github.com/gturri/aXMLRPC .
Which library do you recommend ?
Can I use Retrofit to make xml-rpc request ?
Thanks for any help

1 Answer 1

3

You just use retrofit like this:

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

You must add SimpleXmlConverter:

Retrofit retrofit = new Retrofit.Builder()
            .client(builder.build())
            .baseUrl(YOUR_BASE_URL)
            .addConverterFactory(SimpleXmlConverterFactory.create())
            .build();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.