User-Agent required in some Web APIs
frmichel opened this issue · comments
Hi again Markus,
A weird issue that I got while querying MusicBrainz (I wanted to apply a JSON-LD profile to the response): their API requires the client to set a User-Agent header, otherwise it returns an HTTP 403 error
(example: https://beta.musicbrainz.org/ws/2/work/?fmt=json&query=knocking+on+heavens+door).
I fixed it in https://github.com/lanthaler/JsonLD/blob/master/FileGetContentsLoader.php by simply adding a user agent in the $streamContextOptions:
'header' => "Accept: application/ld+json, application/json; q=0.9, /; q=0.1\r\n".
"User-Agent: JsonLD.php\r\n",
Regards,
Franck.