|
本帖最后由 soguifan 于 2015-8-10 09:36 编辑
本人不是学计算机的,工作也与计算机无关,Delphi只是业余爱好而已。wang_80919(Flying Wang)大神所说的“太过低级”的问题,看了上边的讨论[答案就是 使用 THttpEncdong.Url.Encode(TBytes 版本的参数); (很早之前,我们自己研究出的答案)],本人菜鸟还是没看明白,THttpEncdong也不知道是什么东东,最后自己写了个函数,完成了汉字转GB2312 Urlencode。[mw_shl_code=delphi,false]
function MyUrlEncode(const input: string): string; // 汉字转Gb2312 urlencode
var
S: string;
Stream: TStringStream;
B: Byte;
begin
Result := '';
S := '';
try
Stream := TStringStream.Create(input, TEncoding.GetEncoding(936));
for B in Stream.Bytes do
S := Format('%s%%%.2x', [S, B]);
finally
Stream.Free;
end;
Result := S;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := '提交';
Edit2.Text := MyUrlEncode(Edit1.Text); // 结果 %cc%e1%bd%bb
end;
[/mw_shl_code]
|
|