从ksoap2发送的中文字符转换为" ?????"在PHP服务器端

时间:2017-05-11 11:24:33

标签: android web-services soap android-ksoap2

使用kso​​ap2从android发送的数据将中文字符转换为????在服务器端。

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.encodingStyle = "UTF-8";
        envelope.dotNet = false;
        SoapObject request = new SoapObject(ServiceConstants.NAME_SPACE, methodName);


        //Pass value for user name variable of the web service
        PropertyInfo mapIdProp =new PropertyInfo();
        mapIdProp.setName("mapID");//Define the variable name in the web service method
        mapIdProp.setValue(map_id);//Define value for user name variable
        mapIdProp.setType(String.class);//Define the type of the variable
        request.addProperty(mapIdProp);//Pass properties to the variable

        //Pass value for user name variable of the web service
        try {
            PropertyInfo mapStringProp = new PropertyInfo();
            mapStringProp.setName("mapstring");//Define the variable name in the web service method
            mapStringProp.setValue(mapString);//Define value for user name variable
            mapStringProp.setType(String.class);//Define the type of the variable
            request.addProperty(mapStringProp);//Pass properties to the variable
        }catch (Exception e){
            e.printStackTrace();
        } 

envelope.setOutputSoapObject(request);


HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
    String response_string;
    try {
        ArrayList<HeaderProperty> headerProperty = new ArrayList<HeaderProperty>();

        headerProperty.add(new HeaderProperty("Content-Type", "text/xml"));
        headerProperty.add(new HeaderProperty("charset", "UTF-8"));
        androidHttpTransport.call(SOAP_ACTION, envelope,headerProperty);
        response_string = (String) envelope.getResponse();
        if(response_string!=null){
            Log.d("AsyncCall", "----Response is---"+response_string);
            return response_string;
        }

    } catch (Exception e) {
        e.printStackTrace();
        Log.d("AsyncCall", "----Response not received---");
    }

我的mapstring数据以中文格式发布:汉字/汉字。数据以中文格式发送,但在服务器端,它会自动转换为????。 我的soap webservice已经用UTF-8字符集编码

0 个答案:

没有答案