lanthaler / JsonLD

JSON-LD processor for PHP
MIT License
336 stars 61 forks source link

User-Agent required in some Web APIs #82

Closed frmichel closed 5 years ago

frmichel commented 6 years ago

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.