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.XM LHTTP")
objHTTP.Open "POST", "CBSTW1002_add_upd.asp?Act ion=DB", false
objHTTP.SetRequestHeader "Content-Type" _
, "application/x-www-form-ur lencoded"
objHTTP.Send(xmlMaster.xml )
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.XM
objHTTP.Open "POST", "CBSTW1002_add_upd.asp?Act
objHTTP.SetRequestHeader "Content-Type" _
, "application/x-www-form-ur
objHTTP.Send(xmlMaster.xml
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.XM LHTTP")
'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.XM LHTTP")
'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-ur lencoded"
objHTTP.SetRequestHeader "Content-Length", _
Len(xmlMaster.xml)
objHTTP.Send(xmlMaster.xml )
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.XM
'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.XM
'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-ur
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.
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.
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?Acti on=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</Butto n>
<Button ID=cmdCancel Accesskey=c Class=clsButton01><u>C</u> ancel</But ton>
</td>
</tr>
</Table>
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?Acti
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>
<Button ID=cmdCancel Accesskey=c Class=clsButton01><u>C</u>
</td>
</tr>
</Table>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Anyway, thanks for your help.
ASKER
Thank you HTH. Your method is ok for my problem and now my program can work in the Chinese system.
<script language="JScript">
function PostOrder(xmldoc)
{
var xmlhttp = new ActiveXObject("Msxml2.XMLH
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("Msxml
doc.load(Request);
// HERE the document is in doc!
var result = Server.CreateObject("Msxml
// 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