怎么把勉強 转换成浏览器中可以识别的%E5%8B%89%E5%BC%B7

解决方案 »

  1.   

    static int UrlEncodeChunk(BYTE ch, LPTSTR pszOutput)
    {
       return wsprintf(pszOutput, "%%%.2x", ch);
    }int UrlEncode(LPCTSTR lpszSource, LPTSTR lpszBuffer, DWORD dwSize)
    {
       LPTSTR pCursor=(LPTSTR)lpszSource;
       TCHAR ch;
       LPTSTR pOutput=lpszBuffer;
       while(ch=*pCursor++)
      {
         pOutput+=UrlEncodeChunk(ch, pOutput);
      }
      *pOutput=0;
      return pOutput-lpszBuffer;
    }
      

  2.   

    UrlEscape/UrlUnescape 
    http://msdn2.microsoft.com/en-us/library/ms628636.aspx
      

  3.   

    自己写的一个小程序,呵呵。
    URL编码的规则: 
      1、对每个字节进行编码; 
      2、在 <input> 中输入的空格转为"+"号; 
      3、安全字符不编码 
      4、其他字节以十六进制显示并加"%"前缀。 安全字符的判断标准: 
    所有的字母、数字和如下几个字符:       '\'、   '('、')'、'*'、   '-'、'.'、'_'、'!'  inline BOOL bIsURLSafeCode(TCHAR ch)
    {
    if ((((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))) || ((ch >= '0') && (ch <= '9')))
    {
    return TRUE;
    } switch (ch)
    {
    case '\'':
    case '(':
    case ')':
    case '*':
    case '-':
    case '.':
    case '_':
    case '!':
    return TRUE;
    }

    return FALSE;
    }/************************************************************************************************************************
    对URL进行编码
    如果-1则失败,其它值返回编码之后的字符串长度.
    bIsInput:标识是否是Input中的内容,因为在这个位置的空格编码和URL中的不一样。input中的空格编码成+
    ************************************************************************************************************************/
    int CMyGetWebData::UrlEncode(TCHAR *pszTargetStr, CString &cOutStr, BOOL bIsInput)
    {
    int iStrlen = 0, iBufLen = 0, i = 0, j = 0;
    TCHAR *pszEncodeBuf = NULL;
    unsigned char       ch; iStrlen = (int)strlen(pszTargetStr);
    if(iStrlen == 0)
    {
    return -1;
    }

    //按照编码字符串长度的三倍申请BUFFER,因为一个字符最多编码三个,%20。
    iBufLen = iStrlen * 3;
    if((pszEncodeBuf = (TCHAR*)malloc(iBufLen)) == NULL)
    {
    return -1;
    } //开始编码
    for(i = 0, j = 0; i < iStrlen; i++)
    {
    TCHAR szTemp[256]; ch = pszTargetStr[i];

    if(bIsURLSafeCode(ch))
    {
    pszEncodeBuf[j] = ch;
    j++;
    }
    else
    {
    if(bIsInput && (ch == ' ') ) //input中的空格编码
    {
    pszEncodeBuf[j] = '+';
    j++;
    }
    else
    {
    _stprintf_s(szTemp, 256, "%%%2x", ch);
    memcpy(&pszEncodeBuf[j], szTemp, 3);
    j += 3;
    }
    }
    }

    pszEncodeBuf[j] = '\0';
    cOutStr = pszEncodeBuf; ASSERT((int)strlen(pszEncodeBuf) == cOutStr.GetLength()); return cOutStr.GetLength();
    }
      

  4.   

    http://www.vckbase.com/document/viewdoc/?id=1730URL编码
      

  5.   

    static   int   UrlEncodeChunk(BYTE   ch,   LPTSTR   pszOutput) 

          return   wsprintf(pszOutput,   "%%%.2x ",   ch); 
    } int   UrlEncode(LPCTSTR   lpszSource,   LPTSTR   lpszBuffer,   DWORD   dwSize) 

          LPTSTR   pCursor=(LPTSTR)lpszSource; 
          TCHAR   ch; 
          LPTSTR   pOutput=lpszBuffer; 
          while(ch=*pCursor++) 
        { 
              pOutput+=UrlEncodeChunk(ch,   pOutput); 
        } 
        *pOutput=0; 
        return   pOutput-lpszBuffer; 
    }