简要地说:我的xml字符串编码错误。但是在使用NSLog并从Xcode控制台复制字符串后,字符串得到了正确的编码。
完整说明:
我使用ASIFormDataRequest和encoding:
将xml字符串发送到服务器<?xml version="1.0" encoding="UTF-8"?>
我收到错误500“服务器无法解析您的xml”。我想,这是我的xml中的一个错误。我试图分析,我从NSArray和NSDictionary的字符串中构建了xml。这些字符串取自先前的服务器响应和文本字段。
但后来我使用了NSLog("%@", myXmlString)
。我在Xcode控制台中看到了我的xml字符串。我从控制台复制了字符串并直接粘贴在代码中,然后我将这个字符串字符串发送到服务器。而且没有错误。
问题:如何更改字符串(字符串编码)的方式与Xcode控制台更改方式相同?
更新
NSLog控制台中的字符串:
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://com.test/types/AstoriaObjectProperties" xmlns:ns1="http://com.test/wsdl/AstoriaObjectProperties" xmlns:ns2="http://java.sun.com/jax-rpc-ri/internal"><env:Body><ns1:setObjectProperties env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><HashMap_1 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID1"/></item></HashMap_1><HashMap_2 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID2"/></item></HashMap_2></ns1:setObjectProperties><ns0:ArrayOfhashMap id="ID1" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap><ns0:ArrayOfhashMap id="ID2" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap></env:Body></env:Envelope>
我使用wireshark来获取字符串服务器。这是:
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://com.test/types/AstoriaObjectProperties" xmlns:ns1="http://com.test/wsdl/AstoriaObjectProperties" xmlns:ns2="http://java.sun.com/jax-rpc-ri/internal"><env:Body><ns1:setObjectProperties env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><HashMap_1 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID1"/></item></HashMap_1><HashMap_2 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID2"/></item></HashMap_2></ns1:setObjectProperties><ns0:ArrayOfhashMap id="ID1" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]">...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap><ns0:ArrayOfhashMap id="ID2" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]">...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap></env:Body></env:Envelope>
所以,我在这个xml中看到了额外的点。