在android中为ksoap2设置编码utf-8

时间:2011-09-08 09:08:01

标签: android ksoap2

我有ksoap2的问题,我想在android中为ksoap2设置编码utf-8,或者在header中设置content-type是text / xml,charset = utf = 8, 我的代码: //设置编码

envelope.encodingStyle = "utf-8";

//设置标题

envelope.headerOut = new Element[1];
envelope.headerOut[0] = buildAuthHeader();

private Element buildAuthHeader() {
    String namesc = "http://xml.apache.org/xml-soap";
    Log.i("---build--","--buildAuthHeader--->");
    Element h = new Element().createElement(namesc, "Headers");
    Element username = new Element().createElement(namesc, "Content-Type");
    username.addChild(Node.TEXT, "text/xml;charset=UTF-8");
    h.addChild(Node.ELEMENT, username);

    return h;
}

但不行。请帮我。 感谢。

1 个答案:

答案 0 :(得分:0)

我相信它是这样完成的:

HttpTransportSE transport = new HttpTransportSE(URL, TIME_OUT);
transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");