Dear ALL,
I have a simple test program which fetches a Wikipedia article for a given scientific name and presents the article summary:
program wiki_test;
{$APPTYPE CONSOLE}
{$mode objfpc}{$H+}
uses Classes, TypInfo,SysUtils, fphttpclient, fpjson, jsonparser, opensslsockets;
const
url = 'https://en.wikipedia.org/api/rest_v1/page/summary/';
searchName = 'Vicia faba'; // <--- This works
searchName = 'Loxodonta africana'; // <--- This does NOT work
var
jData: TJSONData;
jItem, jItems: TJSONData;
i: integer;
begin
WriteLn('Searching Wikipedia for: ' + searchName);
// Get the page summary
jData := GetJSON(TFPHTTPClient.SimpleGet(url + StringReplace(searchName, ' ', '_', [rfReplaceAll])));
WriteLn(jData.FindPath('extract').AsString);
WriteLn;
jData.Free;
end.
For some species (eg.,
Vicia faba) it works fine, but for others (eg.,
Loxodonta africana), the program throws an exception: "EHTTPClient: Unexpected response status code: 302".
According to here (
https://blog.airbrake.io/blog/http-errors/302-found), this error arises when "the requested resource has been temporarily moved to a different URI", which suggests that HTTPClient is not handling the (somewhat strange?) redirection of pages performed by Wikipedia.
Could someone help me to sort out - and hopefully solve - this problem?
Thanks in advance!
With warmest regards,