12-05-2018, Saat: 21:33
@epikbalad Benim yaptığım projelerin %99 u netsis ile ilgili sanırım sen netsisin REST Netopenx ile ilgili bilgi istiyorsun. Bununla ilgili bir projem olmadı ama deneme yapmıştım. Bu kodlar inşallah işine yarar.
Konuyu yanlışda anlamış olabilirim.
Konuyu yanlışda anlamış olabilirim.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//şirket Bilgisi
procedure TForm1.GetResponse(aURL: string; memstr: TMemoryStream);
begin
if (aURL <> '') and (memstr <> nil) then
begin
NetHTTPRequest1.Get(aURL, memstr);
end;
end;
function TForm1.GetRespString(aURL: string): string;
var strstr: TStringStream;
begin
strstr := TStringStream.Create;
try
GetResponse(aURL, strstr);
Result := strstr.DataString;
finally
strstr.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
VAR
X: ISuperObject;
begin
Memo1.Lines.Text:=GetRespString('http://192.168.1.13:7070/api/v2/public/AuthorizedBranches?company=DEMO&username=NETSIS');
X := SO(memo1.Text);
edit2.text:= X['"SubeKodu"'].AsString;
edit3.text:= X['"SubeIsmi"'].AsString;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//token alma
procedure TForm1.Button1Click(Sender: TObject);
var
X: ISuperObject;
PostData: TStringList;
rta: string;
IdHTTP1: TIdHTTP;
begin
PostData := TStringList.Create;
try
PostData.Add('grant_type=password');
PostData.Add('branchcode=0');
PostData.Add('password=net1');
PostData.Add('username=NETSIS');
PostData.Add('dbname=DEMO');
PostData.Add('dbuser=TEMELSET');
PostData.Add('dbpassword=');
PostData.Add('dbtype=0');
IdHTTP1:=TIdHTTP.Create(nil);
IdHTTP1.Request.Referer := 'http://192.168.1.13:7070/api/v2/token';
rta := IdHTTP1.Post('http://192.168.1.13:7070/api/v2/token', PostData);
finally
PostData.Free;
FreeAndNil(IdHTTP1);
end;
Memo1.Lines.Text := rta;
X := SO(memo1.Text);
MEMO2.Lines.Clear;
Memo2.Lines.Text:= 'Authorization=Bearer ' + X['"access_token"'].AsString;
edit3.text:= X['"refresh_token"'].AsString;//token
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//cari bilgisi
function TForm1.DoHttpRequest(const AMethod, AResource: string; AHeaders: TStrings; ARequestBody: TStream = nil): string;
var
LURL, LName: string;
LHeader: TNetHeader;
LHeaders: TNetHeaders;
LResponse: IHTTPResponse;
LIndex: Integer;
strstr: TStringStream;
begin
strstr := TStringStream.Create;
LURL:='http://192.168.1.13:7070/api/v2/ARPS?limit=0&offset=0&sort=CARI_KOD AS';
for LIndex := 0 to AHeaders.Count - 1 do
begin
LName := AHeaders.Names[LIndex];
LHeader := TNetHeader.Create(LName, AHeaders.Values[LName]);
LHeaders := LHeaders + [LHeader];
end;
if AMethod = sHTTPMethodGet then
LResponse := NetHTTPRequest1.Get(LURL, nil,LHeaders)
else if AMethod = sHTTPMethodPost then
LResponse := httpRequest.Post(LURL, ARequestBody, nil, LHeaders);
Result := LResponse.ContentAsString();
MEMO1.Lines.Add('Operation done......');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
LJSON: TJSONValue;
LRes: string;
begin
MEMO1.Lines.Add('Getting Private Resource (auth required)');
LRes := DoHttpRequest(sHTTPMethodGet, '', MEMO2.Lines); // yukarıdaki memo2 Memo2.Lines.Text:= 'Authorization=Bearer ' + X['"access_token"'].AsString;
LJSON := TJSONObject.ParseJSONValue(LRes);
try
MEMO1.Lines.Text := TJson.Format(LJSON);
finally
LJSON.Free;
end;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

