Created
October 11, 2018 11:50
-
-
Save nalgeon/81e6f287fb20ca5f24dca896527329b6 to your computer and use it in GitHub Desktop.
Пример работы с подсказками DaData.ru на Delphi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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