我必须以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,但不知道如何使用它。任何帮助表示赞赏。
答案 0 :(得分:2)
如果您确定您的XML是服务器所期望的,我建议您尝试使用RequestMaker来查看问题是否与Android有关。您还可以修改编码和HTTP标头元素以测试各种选项。
我认为您的目的是将SOAP用于Web服务请求,但您的XML片段绝对不是SOAP!在此处查找调用SOAP Web服务的分步指南:LINK