Unit unit1;
Interface
Uses
Winapi. Windows, winapi. Messages, system. sysutils, system. variants,
System. Classes, VCL. Graphics,
VCL. Controls, VCL. Forms, VCL. dialogs, VCL. stdctrls, idbasecomponent,
Idcomponent, idtcpconnection, idtcpclient, idhttp, Web. httpapp;
Type
Tform1 = Class (tform)
HTTP: tidhttp;
Button1: tbutton;
Memo1: tmemo;
Procedure button1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
// Convert Chinese to JavaScript strings
Function encodejsstr (const value: widestring): widestring;
VaR
P: pwidechar;
Begin
Result: = '';
P: = pwidechar (value );
While P ^ <> #0 do
Begin
Case P ^
'"','\','/':
Result: = Result + '\' + P ^;
# $08:
Result: = Result + '\ B ';
# $ 0C:
Result: = Result + '\ F ';
# $ 0a:
Result: = Result + '\ n ';
# $ 0d:
Result: = Result + '\ R ';
# $09:
Result: = Result + '\ T ';
Else
If word (P ^)> $ FF then
Result: = Result + lowercase (format ('\ U % x', [word (P ^)])
Else
Result: = Result + P ^;
End;
INC (P );
End;
End;
// Restores a javascript string to a Chinese character
Function decodejsstr (const value: widestring): widestring;
VaR
P: pwidechar;
V: widechar;
TMP: widestring;
Begin
Result: = '';
P: = pwidechar (value );
While P ^ <> #0 do
Begin
V: = #0;
Case P ^
'\':
Begin
INC (P );
Case P ^
'"','\','/':
V: = P ^;
'B ':
V: = # $08;
'F ':
V: = # $ 0C;
'N ':
V: = # $ 0a;
'R ':
V: = # $ 0d;
'T ':
V: = # $09;
'U ':
Begin
TMP: = copy (p, 2, 4 );
V: = widechar (strtoint ('$' + TMP ));
INC (p, 4 );
End;
End;
End;
Else
V: = P ^;
End;
Result: = Result + V;
INC (P );
End;
End;
Function urlencode (STR: string): string;
VaR
B: byte;
Begin
For B in bytesof (utf8encode (STR) do
Result: = format ('% S %. 2x', [result, B]);
End;
Procedure tform1.button1click (Sender: tobject );
VaR
S, R: string;
Begin
// S: = urlencode ('yunnan studio ');
// S: = httpencode (ansitoutf8 ('yunnan studio '));
S: = httpencode (utf8encode ('yunnan studio '));
R: = http. Get ('HTTP: // localhost: 8080/YN/rest/tservermethods1/ECHO/'+ S );
// Memo1.text: = httpdecode (R );
Memo1.text: = decodejsstr (R );
End;
End.