android webservice(cfx) 乱码

来源:互联网 发布:免费的数据挖掘软件 编辑:程序博客网 时间:2024/06/07 16:05
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;                          //传输回来的String ,用标红  这段代码进行转码,就可以获取中文的数据 String utfString = "";try {utfString = new String(result.toString().getBytes("ISO-8859-1"), "GBK");} catch (UnsupportedEncodingException e) {e.printStackTrace();} return utfString;}  

0 0
原创粉丝点击