Skip to content

Instantly share code, notes, and snippets.

@nalgeon
Created October 11, 2018 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nalgeon/81e6f287fb20ca5f24dca896527329b6 to your computer and use it in GitHub Desktop.
Save nalgeon/81e6f287fb20ca5f24dca896527329b6 to your computer and use it in GitHub Desktop.
Пример работы с подсказками 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