1

我必须以 xml 的形式在服务器上请求并获得响应。目前我收到 xml 不正确的错误。不知道哪里不对或者我的方法不对。下面是我正在尝试的 Xml 和代码。

XML:

<txn><ssl_merchant_id>893</ssl_merchant_id>
<ssl_user_id>page</ssl_user_id><ssl_pin>3472</ssl_pin>
<ssl_test_mode>false</ssl_test_mode><ssl_transaction_type>ccsale
</ssl_transaction_type><ssl_card_number>1234567890123456
</ssl_card_number><ssl_exp_date>1617</ssl_exp_date><ssl_amount>
</ssl_amount></txn>

我试过的代码:

try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("https://demo.myvirtualmerchant.com/VirtualMerchantDemo/processxml.do");

            try {
                StringEntity se = new StringEntity( "<txn><ssl_merchant_id>893</ssl_merchant_id>"+
                        "<ssl_user_id>page</ssl_user_id><ssl_pin>3472</ssl_pin>"+
                        "<ssl_test_mode>false</ssl_test_mode><ssl_transaction_type>ccsale"+
                        "</ssl_transaction_type><ssl_card_number>1234567890123456"+
                        "</ssl_card_number><ssl_exp_date>1617</ssl_exp_date><ssl_amount>1.00"+
                        "</ssl_amount></txn>", HTTP.UTF_8);
                se.setContentType("text/xml");
                httppost.setHeader("Content-Type","application/soap+xml;charset=UTF-8");
                httppost.setEntity(se);

                HttpResponse httpresponse = httpclient.execute(httppost);
                String response_string = EntityUtils.toString(httpresponse.getEntity());
                Log.d("request", response_string);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

我得到的回应如下

<?xml version="1.0" encoding="UTF-8"?>
<txn><errorCode>6042</errorCode><errorName>Invalid Request Format</errorName><errorMessage>XML request is not well-formed or request is incomplete.</errorMessage></txn>

请建议我如何摆脱这个问题。我听说过 SOAP,但不知道如何使用它。任何帮助表示赞赏。

4

1 回答 1

2

如果您确定您的 XML 是服务器所期望的,我建议您尝试使用RequestMaker来查看问题是否真的与 Android 相关。您还可以修改编码和 HTTP 标头元素以测试各种选项。

我认为您的意图是将 SOAP 用于 Web 服务请求,但您的 XML 片段绝对不是 SOAP!在此处找到调用 SOAP Web 服务的分步指南:链接

于 2013-10-31T14:41:33.667 回答