Link to home
Start Free TrialLog in
Avatar of alan_cheung
alan_cheung

asked on

XMLHTTP.SetRequestHeader & Chinese encoding

Dear all,

I've a question about SetRequestHeader metod in Miscosoft.XMLHTTP.

In the following vb script in ASP file, my program is not function correctly if xmlMaster.xml includes Chinese characters.  I think the problem is due to incorrect character encoding of objHTTP.SetRequestHeader.

Is anybody know what parameter is required of SetRequestHeader if Chinese character includes in xmlMaster.xml?

Thanks.

==================================================

  Set objHTTP = CreateObject("Microsoft.XMLHTTP")
  objHTTP.Open "POST", "CBSTW1002_add_upd.asp?Action=DB", false
  objHTTP.SetRequestHeader "Content-Type" _
                         , "application/x-www-form-urlencoded"
  objHTTP.Send(xmlMaster.xml)
Avatar of BigRat
BigRat
Flag of France image

The following sends an XML docuent to the server :-

<script language="JScript">
  function PostOrder(xmldoc)
  {    
    var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
    xmlhttp.Open("POST", "http://myserver/orders/processorder.asp", false);
    xmlhttp.Send(xmldoc);
  }
</script>

You don't need to set any RequestHeaders and you send the XML DOM Object with the Send method. (Not the text!)

When this arrives at the server :-

<%@ language=javascript %>
<%
    // Load the posted XML document.
    var doc = Server.CreateObject("Msxml2.DOMDocument.4.0");
    doc.load(Request);
   // HERE the document is in doc!
    var result = Server.CreateObject("Msxml2.DOMDocument.4.0");
    // Now process the order and build the result document.
    Response.ContentType = "text/xml";
    result.save(Response);
%>

(The code examples are extracted from MSDN) As far as I am aware the XML document is transfered transparently. There is no need to set any other parameters.

HTH
alan,

you can only do one of the following and not both.

1. Post XML Data To The Server
2. Post FORM Data To The Server VIA the POST HTTP Header.

You cannot mix the two up.

To Post XML DATA, you do not need to set any headers.

Set objHTTP = CreateObject("Microsoft.XMLHTTP")
'NO EXTRANEOUS DATA IN THE URL PLEASE
'THIS IS A POST AND NOT GET METHOD
objHTTP.Open "POST", "CBSTW1002_add_upd.asp", false
objHTTP.Send xmlMaster

To Post FORM DATA
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
'NO EXTRANEOUS DATA IN THE URL PLEASE
'THIS IS A POST AND NOT A GET METHOD
objHTTP.Open "POST", "CBSTW1002_add_upd.asp", false
objHTTP.SetRequestHeader "Content-Type",_
 "application/x-www-form-urlencoded"
objHTTP.SetRequestHeader "Content-Length", _
 Len(xmlMaster.xml)
objHTTP.Send(xmlMaster.xml)

Now, is there any reason why you cannot use the POST XML DATA instead of the FORM DATA as in
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q290591

The drawback on the client in posting FORM DATA is that the call MUST be asynchronous and encoding issues MAY be a problem.

Posting the XML DATA will protect your chinese encoding, provided you specify the correct encoding attribute in the xml pi.

My question to you alan is this: Why are you posting FORM DATA. If that is what you are doing, post it thru the traditional way via a IHTML FORM Element. If you want to post XML DATA, then do it as outlined by BigRat and the code provided by me.
Avatar of alan_cheung
alan_cheung

ASKER

Thanks you all of your reply.

For the question raised by b1xml2, I need to posting FORM DATA because the xmlMaster in fact is a Data Island binded to the form.  When user click the Save button, the Data Island will be updated according to the form information.  Finally, a dll file will be called in CBSTW1002_add_upd.asp?Action=DB and information of xmlMaster will updated in DB.

For your reference, here is the sample of Data Island xmlMaster :

<xml id=xmlMaster>
<?xml version="1.0" encoding="BIG5">
<list>
  <row>
    <EngName>Alan</EngName>
    <ChiName>XXX</ChiName>
  </row>
</list>
</xml>


And the form binded with xmlMaster is as follow :

<Table width=550px>
  <tr>
    <td>
      <Fieldset>
        <Table Class=clsLabel01 DataSrc=#xmlMaster>

          <tr>
            <td></td>
            <td>English Name :</td>
            <td>
              <Input ID=txtEngName Class=clsInput type=text size=5 MaxLength=3
                     DataFld="EngName" style="text-transform: uppercase;">
            </td>
          </tr>

          <tr>
            <td></td>
            <td>Chinese Name :</td>
            <td>
              <Input ID=txtChiName Class=clsInput type=text size=5 MaxLength=3
                     DataFld="ChiName" style="text-transform: uppercase;">
            </td>
          </tr>

        </Table>
      </Fieldset>
    </td>
  </tr>

  <tr>
    <td align=right>
      <Button ID=cmdSave Accesskey=s Class=clsButton01><u>S</u>ave</Button>
      <Button ID=cmdCancel Accesskey=c Class=clsButton01><u>C</u>ancel</Button>
    </td>
  </tr>  
 
</Table>
ASKER CERTIFIED SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for BigRat details explaination.  I'll try your suggestion in this week end and see if it can solve my problem.  So, maybe reply and let u know if this solution work later.
Anyway, thanks for your help.
Thank you HTH.  Your method is ok for my problem and now my program can work in the Chinese system.