I am trying to get the data from a web service, this is the code I use:
Client: HttpClient;
Request: HttpRequestMessage;
Response: HttpResponseMessage;
Content: HttpContent;
JsonResponse: Text;
JsonObject: JsonObject;
RecordJson: JsonObject;
ServiceUrl: Text;
Username: Text;
Password: Text;
companyinfo: Record "Company Information";
begin
companyinfo.FindSet();
ServiceUrl := 'http://192.168.1.1:7049/DynamicsTest/ODataV4/Company(' + companyinfo.companyserviceweb + ')/customers';
Username := 'SERVER\SYSTEMTEST';
Password := '123456';
Client.DefaultRequestHeaders.Clear();
Client.DefaultRequestHeaders.Add('Authorization', 'Basic' + Base64Encode(Username + ':' + Password));
Request.SetRequestUri(ServiceUrl);
Request.Method := 'GET';
if Client.Send(Request, Response) then begin
Content := Response.Content();
Content.ReadAs(JsonResponse);
JsonObject.ReadFrom(JsonResponse);
Message(JsonResponse);
end else begin
Error('Error: ' + Format(Response.HttpStatusCode));
end;
end;