Skip to content

Instantly share code, notes, and snippets.

@nalgeon
Created Oct 11, 2018
Embed
What would you like to do?
Пример работы с подсказками DaData.ru на Delphi
function Suggest(DictionaryType, ContentType, Accept, Token, Body: string): string;
var
IdHTTP1: TIdHTTP;
StringStream: TStringStream;
begin
IdHTTP1 := TIdHTTP.Create;
StringStream := TStringStream.Create('', TEncoding.UTF8);
try
IdHTTP1.HTTPOptions := [hoKeepOrigProtocol,hoForceEncodeParams,hoNoProtocolErrorException,hoWantProtocolErrorContent];
IdHTTP1.Request.ContentEncoding := 'UTF-8';
IdHTTP1.Request.ContentType := ContentType;
IdHTTP1.Request.Accept := Accept;
IdHTTP1.Request.CustomHeaders.Add('Authorization: Token ' + Token);
StringStream.WriteString(Body);
Url := 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/' + DictionaryType;
Result := IdHTTP1.Post(Url, StringStream);
finally
StringStream.Free;
IdHTTP1.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
DictionaryType: string;
ContentType: string;
Accept: string;
Token: string;
Body: string;
begin
DictionaryType := 'party';
ContentType := 'application/json';
Accept := 'application/json';
Token := '***';
Body := '5408110390';
Memo1.Text := Suggest(DictionaryType, ContentType, Accept, Token, Body)
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment