简体   繁体   中英

Error in RestSharp Request? , XML , The ':' character, hexadecimal value 0x3A, cannot be included in a name

The : character , hexadecimal value 0x3A , cannot be included in a name.

I get the above error from the API while parsing an XML body in a RestSharp POST Request.

What could I do?

  string xmlBody = "<soap:Envelope" +
                      " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
                      " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
                      " xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
                      "<soap:Body> " +
                          "<MainField " +
                               " xmlns =\"http://www.w3.org\">" +
                               "<Username>string</Username> " +
                               "<Password>string</Password> " +
                               "<FieldPlace> " +
                                   "<Value1>string</Value1> " +
                                   "<Value2>string</Value2> " +  
                               "</FieldPlace> " +
                          "</MainField> " +
                      "</soap:Body> " +
                   "</soap:Envelope>";

  requestPost.AddParameter("text/xml", xmlBody, "text/xml" , ParameterType.RequestBody);

This is the XML


<soap:Envelope
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Body>
        <MainField>
              xmlns ="http://www.w3.org">
            <Username>string</Username>
            <Password>string</Password>
            <FieldPlace>
                <Value1>string</Value1>
                <Value2>string</Value2>
            </FieldPlace>
        </MainField>
    </soap:Body>
</soap:Envelope>


Please try with this corrected XML and let me know if that works for you.

Couple of points to note:

    1. Missing spaces on the xmlns at the soap:Envelope element .
    1. The MainField element was closed before adding the namespace.
string xmlBody = "<soap:Envelope" +
                 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
                 " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
                 " xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
                     "<soap:Body> " +
                         "<MainField " +
                              "xmlns=\"http://www.w3.org/2003/05/soap-envelope\" > " +
                              "<Username>string</Username> " +
                              "<Password>string</Password> " +
                              "<FieldPlace> " +
                                  "<Value1>string</Value1> " +
                                  "<Value2>string</Value2> " +
                              "</FieldPlace> " +
                         "</MainField> " +
                     "</soap:Body> " +
                  "</soap:Envelope>";

I'd also recommend using an alternative method to generate the XML string , perhaps the System.Xml.XmlWriter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM