Client.DefaultRequestHeaders.Add('AuthToken', AuthToken); if Carrier <> '' then Client.DefaultRequestHeaders.Add('Carrier', Carrier); clear(tempBlob); clear(lInStream); clear(lOutStream); tempBlob.Blob.CreateOutStream(lOutStream); tempBlob.Blob.CreateInStream(lInStream); XMLParServ.Init(Postcode, CountryCode); XMLParServ.SetDestination(lOutStream); XMLParServ.Export; while not lInStream.EOS do begin lInStream.ReadText(TextXMLReq); TextXMLReqFull := TextXMLReqFull + TextXMLReq; end; Content.WriteFrom(TextXMLReqFull); Client.Post(URLString, Content,Response); if not Response.IsSuccessStatusCode then Error(WebServiceErr, Response.HttpStatusCode, Response.ReasonPhrase); clear(lInStream); Response.Content.ReadAs(TextXMLReqFull); // Response.Content.ReadAs(lInStream);
<?xml version="1.0" encoding="UTF-8"?> <ParcelServiceResponse> <Status>Success</Status> <Carriers> <Carrier Name="ABC" ServiceID="1" ServiceName="24hr" ParcelCost="1.23" Currency="GBP" /> <Carrier Name="ABC" ServiceID="2" ServiceName="48hr" ParcelCost="2.34" Currency="GBP" /> </Carriers> </ParcelServiceResponse>
XmlDocument.ReadFrom(lInStream, lXmlDocument); if lXmlDocument.SelectSingleNode('//Status', lXmlNode) then respStatus := lXmlNode.AsXmlElement.InnerText;
if lXmlDocument.SelectNodes('//Carriers/Carrier', lXmlNodeList) then begin foreach lCarriersNode in lxmlnodelist do begin if lCarriersNode.SelectSingleNode('ServiceID', lXmlNode) then respServices := respServices + lXmlNode.AsXmlElement.InnerText; end; end;
Comments
for reference I've used this helper function:
Below is how I used the function to get the attribute value:
Now I need to figure out why I get a response from endpoint saying "please contact administrator" if I stream the request to the endpoint as below instead of passing the text variable.