html代码:
<html>
 <head>
  <title>test</title>
 
 </head> <body>
<form method="post" action="http://www.icmeter.com:60000">
<textarea name="xmlData" rows="10" cols="50">
<RD>
<Task ID="14567" TYPE="CMD" />
<CJQ ID="1"/>
<CMD DATA="6820AAAAAAAAAAAAAA0303810AC016" />
</RD>
</textarea>
<input type="submit" value="提交">
  </form>
 </body>
</html>提交后服务器端收到:xmlData=%3CRD%3E%0D%0A%3CTask+ID%3D%2214567%22+TYPE%3D%22CMD%22+%2F%3E%0D%0A%3CCJQ+ID%3D%221%22%2F%3E%0D%0A%3CCMD+DATA%3D%226820AAAAAAAAAAAAAA0303810AC016%22+%2F%3E%0D%0A%3C%2FRD%3E%0D%0A%09问:这个编码怎样处理比较合适?

解决方案 »

  1.   

    客户端POST一个XML,一般怎么做的
      

  2.   

    一般情况下,你使用form表达提交的编码很容易处理啊,所有的编码都统一,在服务器端设置request.setCharacterEncoding("UTF-8");就可以了。只有通过url方式提交的中文参数会出现乱码问题不易解决,其他的没问题的
    这个或许对你有些帮助http://blog.csdn.net/elvis_chow/article/details/6722328
      

  3.   

    正常情况下,web 服务器会自动解码传入的参数
    既然你的没有,那么就自己做一下url解码你得到的是一个 xml 文本
    你可以直接用字符串函数处理
    也可以用你的服务器支持的任何一款xml工具进行处理
      

  4.   

    HTTP服务器要我做的。那么需要在我这端做解码了
      

  5.   

    php不太清楚。。asp.net的话会自动解码为对应的字符串,然后使用处理xml的类加载xml字符串得到xmldom就可以操作了,或者直接写入xml文件中
      

  6.   

    %3c表示<可以理解,可是+为什么表示空格呢 
      

  7.   

    你这叫post xml吗?最多是post了一个像xml的字符串.post内容的编码 跟你当前页面的encode(表单所在页面的encode)有很大关系.
      

  8.   

     这是被 escape 过了,不知你后台用什么,应该都有对应的 unescape 方法
    unescape 一下就出来了
     
     
      

  9.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head><body>
    <form enctype="application/x-www-form-urlencoded" accept-charset="utf-8" method="post" action="http://gateway.renzhe.com/">
    <textarea rows="3" cols="60" name="message"></textarea>
    <input type="submit" value="post" />
    </form>
    </body>
    </html>
    PHP<?php
    header('Content-Type: text/xml; charset=utf-8'); 
    $t='<?xml version="1.0" encoding="utf-8"?>';
    $t.=$_POST['message'];echo $t;
    flush(); 
    ?>
      

  10.   

    后台是C++代码,接收到
    xmlData=%3CRD%3E%0D%0A%3CTask+ID%3D%2214567%22+TYPE%3D%22CMD%22+%2F%3E%0D%0A%3CCJQ+ID%3D%221%22%2F%3E%0D%0A%3CCMD+DATA%3D%226820AAAAAAAAAAAAAA0303810AC016%22+%2F%3E%0D%0A%3C%2FRD%3E%0D%0A%09后做解码
      

  11.   

    简单写了个 C++ 的 unescape,没考虑双字字符#include <math.h> 
    #include <iostream>  
    #include <string> 
    using namespace std;long hex2dec(char * s){
    int L=strlen(s);
    char c;
    long re=0;
     while(c=s++[0]){
     if(c >='0' && c <='9'){
    c-=48;
     }else{
     c=c>'Z'? c-32:c; 
    c-='A'-10;
     }
    re+= c*pow(  16 ,--L) ;
     }
     return re;
     } string unescape(char * str){ char* re =(char *)calloc( strlen(str) +1,1);
    char *_str;
    char * _re=re;
    int n;
    char code[5]={0};

     char c;
    while(str){
    _str= strchr(str,'%') ;
    if(!_str) break;
    strset(code,0);
    if(_str[0]=='u'){
    memcpy(code,_str+1,4);
    }else{
    memcpy(code,_str+1,2);
    }
    c=(char)hex2dec(code);
    if( n=_str-str ){
     memcpy(_re,str, n   );
    _re+=n;
    }
    _re[0]=c;
    _re++;
    str=_str+3;
    }
    return re;
    cout << re << endl;  
    }
    int main(int argc, char* argv[])
    {
    char* str="%3CRD%3E%0D%0A%3CTask+ID%3D%2214567%22+TYPE%3D%22CMD%22+%2F%3E%0D%0A%3CCJQ+ID%3D%221%22%2F%3E%0D%0A%3CCMD+DATA%3D%226820AAAAAAAAAAAAAA0303810AC016%22+%2F%3E%0D%0A%3C%2FRD%3E%0D%0A%09";
     
    cout<<  unescape(str)  << endl;
    return 0;
    }