在「XXX.cgi」中、用的是「https」、結果使得参数(文件名)都変成↓這付怪模様
<a href="https://.../xxx.cgi?&dir=xxx&file=%E8%B3%87%E6%96%99%E4%BD%9C%E6%88%90%E4%BE%9D%E9%A0%BC%E6%9B%B8v1.0.xls">因用的是「UrlDownloadToFile」函数自動下載、下載後的文件名也就是↓原様下載
 %E8%B3%87%E6%96%99%E4%BD%9C%E6%88%90%E4%BE%9D%E9%A0%BC%E6%9B%B8v1.0.xls現在想把他還原成真正的文件名(XXX.xls)、該怎麼做尼?

解决方案 »

  1.   

    http://www.scalabium.com/faq/dct0126.htm
    #126: How can I decode http/url value? 
    Everybody, who wrote some tools for web, know that urls/filename/script parameters etc are encoded (contains the %xx substrings).For example,
    http://groups.google.com/groups?q=http%3A%2F%2Fwww.scalabium.com&hl=ru&meta= site%3Dgroups or http://groups.google.com/groups?th=1223ec006df22d25&seekm=3b98e41d_2%40dnewsOf course, in code you must decode a value in "real" value. The algorithm is easiest - after % character the next 2 positions are decimal code of character.But also for this task you can use the HTTPEncode function from HttpApp unit:function HTTPEncode(const AStr: String): String;
    const
      NoConversion = ['A'..'Z','a'..'z','*','@','.','_','-'];
    var
      Sp, Rp: PChar;
    begin
      SetLength(Result, Length(AStr) * 3);
      Sp := PChar(AStr);
      Rp := PChar(Result);
      while Sp^ <> #0 do
      begin
        if Sp^ in NoConversion then
          Rp^ := Sp^
        else
          if Sp^ = ' ' then
            Rp^ := '+'
          else
          begin
            FormatBuf(Rp^, 3, '%%%.2x', 6, [Ord(Sp^)]);
            Inc(Rp,2);
          end;
        Inc(Rp);
        Inc(Sp);
      end;
      SetLength(Result, Rp - PChar(Result));
    end; 
      

  2.   

    也可看看这里:unit DzURL;interfaceuses SysUtils;function UrlEncode(const DecodedStr: String; Pluses: Boolean): String;
    // Encodes standard string into URL data format.
    // Example: http://www.dzsoft.com -> http%3A%2F%2Fwww.dzsoft.com%2F
    // Pluses parameter specifies whether spaces will be 
    // encoded as '+' or as '%20'function UrlDecode(const EncodedStr: String): String;
    // Decodes URL data into a readable string.
    // Example: http%3A%2F%2Fwww.dzsoft.com%2F -> http://www.dzsoft.comfunction HexToInt(HexStr: String): Int64;
    // Taken from http://www.delphi3000.com/article.asp?id=1412implementationfunction UrlEncode(const DecodedStr: String; Pluses: Boolean): String;
    var
      I: Integer;
    begin
      Result := '';
      if Length(DecodedStr) > 0 then
        for I := 1 to Length(DecodedStr) do
        begin
          if not (DecodedStr[I] in ['0'..'9', 'a'..'z',
                                           'A'..'Z', ' ']) then
            Result := Result + '%' + IntToHex(Ord(DecodedStr[I]), 2)
          else if not (DecodedStr[I] = ' ') then
            Result := Result + DecodedStr[I]
          else
            begin
              if not Pluses then
                Result := Result + '%20'
              else
                Result := Result + '+';
            end;
        end;
    end;function UrlDecode(const EncodedStr: String): String;
    var
      I: Integer;
    begin
      Result := '';
      if Length(EncodedStr) > 0 then
      begin
        I := 1;
        while I <= Length(EncodedStr) do
        begin
          if EncodedStr[I] = '%' then
            begin
              Result := Result + Chr(HexToInt(EncodedStr[I+1]
                                           + EncodedStr[I+2]));
              I := Succ(Succ(I));
            end
          else if EncodedStr[I] = '+' then
            Result := Result + ' '
          else
            Result := Result + EncodedStr[I];      I := Succ(I);
        end;
      end;
    end;function HexToInt(HexStr: String): Int64;
    var RetVar : Int64;
        i : byte;
    begin
      HexStr := UpperCase(HexStr);
      if HexStr[length(HexStr)] = 'H' then
         Delete(HexStr,length(HexStr),1);
      RetVar := 0;  for i := 1 to length(HexStr) do begin
          RetVar := RetVar shl 4;
          if HexStr[i] in ['0'..'9'] then
             RetVar := RetVar + (byte(HexStr[i]) - 48)
          else
             if HexStr[i] in ['A'..'F'] then
                RetVar := RetVar + (byte(HexStr[i]) - 55)
             else begin
                Retvar := 0;
                break;
             end;
      end;  Result := RetVar;
    end;end.
    http://www.torry.net/dpfl/dzurl.html
      

  3.   

    hehe, 我明白了。不過、因為Encode函数是別人做的、不知道算法、所以現在還不能很好的還原。
    我自己慢慢試吧、先把帳付了。