The Twitter 1.1/statuses/update.jsonURL expects the data to be encoded in a format application/x-www-form-urlencoded, so you need to set the property TRESTClient.ContentTypeto ctAPPLICATION_X_WWW_FORM_URLENCODED(default is set ctNone).
UTF-8, TRESTClient Indy , Indy , , Embarcadero TRESTClient ( ). , . UTF-8 ( , BTW), Twitter, UTF-8 ( charset Content-Type REST), TRESTClient , . , TRESTClient REST , , , , , .
, EncodeAsUTF8(). UnicodeString, UTF-8, . UTF-8 AnsiString, UTF-16 UniodeString, Ansi RTL, , UTF-8. :
function TTwitterApi.EncodeAsUTF8(UnicodeStr: string): string;
var
UTF8Str: UTF8String;
I: Integer;
begin
UTF8Str := UTF8String(UnicodeStr);
SetLength(Result, Length(UTF8Str));
for I := 1 to Length(UTF8Str) do
Result[I] := Char(Ord(UTF8Str[I]));
end;
TRESTClient UTF-8 POST-. charset Content-Type ( Twitter UTF-8, charset).
, , , TRESTClient , Indy TIdHTTP ( application/x-www-form-urlencoded TRESTClient), :
procedure TTwitterApi.Send(Tweet: string);
var
Params: TStringList;
begin
Reset;
Params := TStringList.Create;
try
FParams.Add('status=' + Tweet);
FIdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
FIdHTTP.Request.Charset := 'utf-8';
FIdHTTP.Post('https://api.twitter.com/1.1/statuses/update.json', Params, IndyTextEncoding_UTF8);
finally
Params.Free;
end;
end;