Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Problems with Indy Post command syntax



Permlink Replies: 1 - Last Post: Apr 9, 2018 3:16 PM Last Post By: Cornelia von Sc...
Cornelia von Sc...

Posts: 21
Registered: 4/26/07
Problems with Indy Post command syntax
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 9, 2018 11:25 AM
I want to use the post command to make this query and then parse out the results:
https://secure.apspaymentgateway.com/api/query.php?username=apsmulticurrency&password=Start123&start_date=20180406000000&end_date=20180406240000 (**)
.......
HTTP := TIdHTTP.Create;
try
PostData := TStringList.Create;
try
szGatewayURL := 'https://secure.apspaymentgateway.com/api/query.php';
szInputStr := 'username=apsmulticurrency&password=Start123&start_date=20180406000000&end_date=20180406240000';
PostData := TStringList.Create;
PostData.Add(szInputStr);
HTTP.Request.ContentType := 'application/x-www-form-urlencoded';
HTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0';

szHTTPResponse := HTTP.Post(szGatewayURL, Postdata);
finally
PostData.Free;
end;
finally
HTTP.Free;
end;
finally
SSLIOHandler.Free;
end;
except
on E: Exception do
begin
Result := 3;
end;
end;

if Trim(szHTTPResponse) <> '' then
begin
try
XMLResponse := LoadXMLData(szHTTPResponse); // this works because when I write it to file it looks like a correct xml doc
XMLResponse.SaveToFile(sfTempPath + 'Query_Output.xml');
finally
XMLResponse._Release;
end;
end;

I have two issues:
1) I always get the response Invalid user-id password, but pasting the url in (**) into your browser yields a whole bunch of results, so something must be incorrect in my input. But what?.
2) I don't think I can use a string to parse the response as the response is 18,0000 bytes and could be even more.The response is xml and I need to parse it out. Should I be using type TStringStream for the response?
Thanks
Cornelia
Cornelia von Sc...

Posts: 21
Registered: 4/26/07
Re: Parsing XML from TStringStream
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 9, 2018 3:16 PM   in response to: Cornelia von Sc... in response to: Cornelia von Sc...
I figured out the first part. And now I get an XML response in PostRes which I have defined as TStringStream.
I get the correct XML response in PostRes. It is thousands of bytes. But I am having trouble parsing it out. What I need to do is find each block delimited by the tags <transaction> and </transaction>.
Here is the code

procedure ParseQueryOutPut(StrQOutput: TStringStream);
var iPos1, iPos2, iTransCount:integer;
begin
StrQOutput.Position := 0;
iTransCount := 0;
while StrQOutput.Position < StrQOutput.Size do
begin
iPos1 := Pos('<transaction>', StrQOutput.dataString);
if iPos1 > 0 then
begin
iPos2 := Pos('</transaction>', StrQOutput.dataString);
end;

if (iPos1 > 0) and (iPos2 > 0) then
begin
szTempStr := Copy(StrQOutput.dataString, iPos1, iPos2- iPos1 + 1 + 14); // add 14 to include the end tag </transaction>
XMLTrans := LoadXMLData(szTempStr);
XMLTransInfo := XMLTrans.DocumentElement; // this returns the root node which is <transaction>
inc(iTransCount);
ParseTransaction(xmlTransInfo, iTransCount);
StrQOutput.Position := iPos2 + 14; //(A)
StrQOutput.Seek(iPos2+14, sofromBeginning); // (B)
end
else
break;
end;
end;

The procedure ParseTransaction works. The problem is that neither (A) nor (B) advance the pointer in the string stream so StrQOutput.dataString, iPos1 and iPos2 return the same value in each iteration and I am stuck in an infinite loop.
What am I doing wrong?
Thanks
Cornelia
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02