maxkleiner / maXbox4

code compiler script studio
GNU General Public License v3.0
23 stars 10 forks source link

winhttprequest object #20

Closed maxkleiner closed 1 year ago

maxkleiner commented 3 years ago

Microsoft Windows HTTP Services (WinHTTP) provides developers with an HTTP client application programming interface (API) to send requests through the HTTP protocol to other HTTP servers.

    // Instantiate a WinHttpRequest object.
   httpReq:= CreateOleObject('WinHttp.WinHttpRequest.5.1');

   // Open an HTTP connection.                
   hr:= httpReq.Open('GET', aURL, false);            
   if hr= 0 then httpReq.setRequestheader('apikey','6b337c92c792174a54acd715ab1aae64'); 

   HttpReq.Send()  /// Send HTTP Request & get Responses.
   writeln(httpReq.responseText)
   writeln(httpReq.GetAllResponseHeaders());         
   httpReq:= NULL;
maxkleiner commented 1 year ago

procedure GetJSONData; var XMLhttp: OleVariant; // As Object Automation ajt: TJson; JObj: TJsonObject2; JArray: TJsonArray2; response,statuscode: string; cnt: integer; //md: TDims; begin
XMLhttp:= CreateOleObject('msxml2.xmlhttp')
XMLhttp.Open('GET', WEBURL, False) //False is async //XMLhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); XMLhttp.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); XMLhttp.Send(); response:= XMLhttp.responseText; //assign the data statuscode:= XMLhttp.status; //writeln(statuscode +CRLF+ response) ajt:= TJson.create(); try ajt.parse(response); except writeln( 'Exception: "" parse error: {'+ exceptiontostring(exceptiontype, exceptionparam)) end; JArray:= ajt.JsonArray; writeln('Get all Titles: '+itoa(jarray.count));
for cnt:= 0 to jarray.count-1 do writeln(itoa(cnt)+' '+Jarray.items[cnt].asObject.values['title'].asString);
ajt.Free; end;