본문 바로가기
Delphi Tip/인터넷

IdHTTP App ID, Key 존재시

by MonoSoft 2021. 12. 10.
728x90
반응형

IdHTTP  App ID, Key 존재시

 

user System.JSON

var

s : String;

JSON : TJSONObject;

i : integer;

rec_Data : TStringStream;

Stream: TBytesStream;

begin

Stream := TBytesStream.Create;

IdHTTP1.Request.CustomHeaders.Add('x-pharmsearch-app: 000000');

IdHTTP1.Request.CustomHeaders.Add('x-pharmsearch-key: 0000000');

IdHTTP1.Request.ContentType := 'application/json; charset=utf-8';

IdHTTP1.Request.ContentEncoding := 'utf-8';

try

IdHTTP1.Get('http://000000000000000000', Stream, []);

Memo1.Text := TEncoding.UTF8.GetString(Stream.Bytes, 0, Stream.Size);

finally

FreeAndNil(Stream);

end;

 

========================2차

user IdHTTP,System.JSON, REST.Json;

 

procedure TForm1.API_Tex_User_Status(sUserID: String; iType: integer);

Const

API_APP : String = '000000000';

API_KEY : String = 'x0000000000000000000';

CONTENTTYPE : String = 'pplication/json; charset=utf-8';

CONTENTENCODENG : String = 'utf-8';

URL_USER_STATUS : String = 'http://00000000000/%s';

var

IdHttp_API : TIdHTTP;

J_Obj : TJSONObject;

J_Value : TJSONValue;

B_Stream : TBytesStream;

begin

IdHttp_API := TIdHTTP.Create;

B_Stream := TBytesStream.Create;

try

try

IdHttp_API.Request.CustomHeaders.Add(API_APP);

IdHttp_API.Request.CustomHeaders.Add(API_KEY);

IdHttp_API.Request.ContentType := CONTENTTYPE;

IdHttp_API.Request.ContentEncoding := CONTENTENCODENG;

IdHttp_API.Get(URL_USER_STATUS, B_Stream, []);

var sJSON : string := TEncoding.UTF8.GetString(B_Stream.Bytes, 0, B_Stream.Size);

J_Obj := TJSONObject.ParseJSONValue(sJSON) as TJSONObject;

J_Value := J_Obj as TJSONValue;

 

Memo1.Lines.Text := TJSON.Format(J_Value);

Memo1.Lines.Add(J_Value.GetValue<string>('statusCode')) ;

Memo1.Lines.Add(J_Value.GetValue<string>('statusDescription')) ;

except on E: Exception do

ShowMessage(E.Message);

end;

finally

FreeAndNil(IdHttp_API);

FreeAndNil(B_Stream);

end;

end;

 

728x90
반응형

댓글