public String soapWebservice(String url, String nameSpace,
String methodName, String soapAction,
LinkedHashMap<String, String> paramMap) {
String URL = url;
String NAME_SPACE = nameSpace;
String METHOD_NAME = methodName;
String SOAP_ACTION = soapAction;
SoapObject sobject = new SoapObject(NAME_SPACE, METHOD_NAME);
for (Entry<String, String> entry : paramMap.entrySet()) {
String value = entry.getValue();
if (value != null) {
sobject.addProperty(entry.getKey(), value);
}
}
HttpTransportSE ht = new HttpTransportSE(URL, 40000);
ht.debug = true;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.bodyOut = sobject;
envelope.encodingStyle = SoapSerializationEnvelope.ENC;
//envelope.encodingStyle = "GBk";
envelope.dotNet = true;
envelope.setOutputSoapObject(sobject);
SoapObject result = null;
try {
ht.call(SOAP_ACTION, envelope);
} catch (Exception e) {
e.printStackTrace();
return "";
}
result = (SoapObject) envelope.bodyIn;
<span data-mce-style="color: #ff0000;" style="color:#ff0000;">//传输回来的String ,用标红 这段代码进行转码,就可以获取中文的数据</span>
<span data-mce-style="color: #ff0000;" style="color:#ff0000;">String utfString = "";
try {
utfString = new String(result.toString().getBytes("ISO-8859-1"), "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}</span>
return utfString;
}