• c++ 对汉字进行url编码(实验管用)


    CString urlEncode(CString s)
    {

     int len = s.GetLength();
     char *out = new char[len*9+1];
     memset(out , 0 , len*9+1);
     int i , j;
     int ch = 0 ;

     static char  myhex[0xFF+1][4];  //add by zhouzd 2008-10-06
     static bool isinital = false;

     if ( !isinital )
     {
      for ( i = 0 ; i <= 0xFF ; ++i )
      {
       myhex[i][0] = '%';
       sprintf( myhex[i]+1 , "%02X" , i );
      }
      isinital = true;
     }

     for (i = 0 , j = 0; i < len ; ++i )
     {
      ch = s.GetAt(i);

      //printf("%c\n" , s.GetAt(i) );

      if ('A' <= ch && ch <= 'Z')         // 'A'..'Z'
      {
       out[j++] = ch;
      }
      else if ('a' <= ch && ch <= 'z')    // 'a'..'z'
      {
       out[j++] = ch;
      }
      else if ('0' <= ch && ch <= '9')    // '0'..'9'
      {
       out[j++] = ch;
      }
      else if (ch == ' ')           // space
      {
       out[j++] = '+';
      }
      else if (ch == '-' || ch == '_'        // 不需要转化
       || ch == '.' || ch == '!'
       || ch == '~' || ch == '*'
       || ch == '\'' || ch == '('
       || ch == ')')
      {
       out[j++] = ch;
      }
      else if (ch <= 0x007f)     // ASCII控制字符
      {   
       strcat(out , myhex[ch]);
       j += 3;
      }
      else if (ch <= 0x07FF)         // 非ASCII <= 0x7FF
      {
       strcat(out , myhex[0xc0 | (ch >> 6)]);
       strcat(out , myhex[0x80 | (ch & 0x3F)]);
       j += 6;
      }
      else                       // 0x7FF < ch <= 0xFFFF
      {
       strcat(out , myhex[0xe0 | (ch >> 12)]);
       strcat(out , myhex[0x80 | ((ch >> 6) & 0x3F)]);
       strcat(out , myhex[0x80 | (ch & 0x3F)]);
       j += 9;
      }
     }
     out[j] = '\0';
     USES_CONVERSION;
     CString result = A2W(out);

     delete out;
     out = NULL;

     return result;
    }

    怎么查看服务器返回值?

     pHTTP->EndRequest(HSR_SYNC);
         
         char strBuff[1025] = {0};
    string strHtml; //是string 不是CString
    while ((pHTTP->Read((void*)strBuff, 1024)) > 0)
    {
    strHtml += strBuff;
    }
    // _cprintf("\n读取内容结束...");

    int unicodeLen = MultiByteToWideChar(CP_UTF8, 0, strHtml.c_str(), -1, NULL, 0);
    WCHAR *pUnicode = new WCHAR[unicodeLen + 1];
    memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));

    MultiByteToWideChar(CP_UTF8,0,strHtml.c_str(),-1, pUnicode,unicodeLen);
    CString str(pUnicode); //这就是要的内容
    delete []pUnicode;

  • 相关阅读:
    SpringBoot项目启动遇到的问题记录
    关于点击按钮提交前进行数据校验
    idea插件的位置
    sqlite
    xamarin.forms 使用依赖注入
    vs2019查找替换,使用正则表达式功能
    EFCore 事务提交
    windows磁盘【文件和文件夹遇到-打不开or不能删除or损坏】的解决方式
    xamarin.forms 中使用Forms9Patch插件来显示图片遇到的问题
    net5 依赖注入的时候,遇到的问题:Cannot consume scoped service from singleton IHostedService
  • 原文地址:https://www.cnblogs.com/zhwl/p/2784891.html
Copyright © 2020-2023  润新知