I'm trying to connect to a REST web service using Delphi 6. I've been able to successfully do this with the code below:
function WSConnect(url: WideString; params: TStringList = nil; method: WideString = 'GET'):WideString;
var
request: XMLHTTP60;
begin
// CreateQueryString below just adds any params passed in to the end of the url
url := url + CreateQueryString(params);
CoInitialize(nil);
request := CoXMLHTTP60.Create;
request.open(method,url,false,'','');
request.send('');
if request.status=200 then
begin
Result := request.responseText;
end else
Result := 'Error: (' + inttostr(request.Status) + ') ' + request.StatusText;
CoUninitialize();
end;
I've pieced together this code from different examples around the net, but I can't find any documentation on CoXMLHTTP60. The code works great, but the current implementation only gives me back a string with the JSON response in it, and I'm struggling to figure out how to pull the properties out of this JSON string in Delphi 6. I've looked at SuperObjects (which people say has problems with Delphi 6 so I didn't try it) and a different project called json4delphi that I couldn't get to compile in Delphi 6 despite it saying it is compatible.
There are also different properties on the CoXMLHTTP60 response object that I believe might get me the values I need. They are:
request.responseBody: OleVariant;
request.responseStream: OleVariant;
request.responseXML: IDispatch;
I would think one of these would provide access to the properties in the JSON, but I can't figure out how to even use them. I'm pretty unfamiliar with IDispatch, once again documentation is difficult to find, and what's there looks very confusing. Some places say to just assign the IDispatch property to an OleVariant and then I can access the properties directly with dot notation, but that doesn't seem to be working either for me, so maybe I'm doing it wrong.
Does anyone have any knowledge on how to pull out the response properties in a CoXMLHTTP60 call?