I'm trying to use the last.fm api using Indy's TIdHTTP
component. When I send a request, I keep receiving Connection closed gracefully
without receiving any data. However, when I copy the same URL from the component (directly to the clipboard) into a web browser such as Chrome or Firefox, it works perfectly fine.
I'm trying to implement the album.search
call, and am trying to GET
the data from this sample URL:
This request is documented here
I have a helper function to concatenate the common URL structure:
function TLastFm.ApiUrl(const Method: String): String;
begin
Result:= Format('http://ws.audioscrobbler.com/%s/?format=json&api_key=%s&method=%s',
[FVersion, FKey, Method]); //FVersion = '2.0', FKey = my API key
end;
And then I make the actual call like this:
var
S, R: String;
begin
S:= ApiUrl('album.search')+'&album='+Album; //Album = 'believe'
S:= S + '&limit=30&page=1';
Clipboard.AsText:= S; //Used to paste into browser to test
FHTTP.Request.UserAgent:= 'Mozilla/3.0 (compatible; JD Test)';
R:= FHTTP.Get(S); //<-- Connection closed gracefully
// ...
end;
How do I make this call successfully using Indy's TIdHTTP
?