LukeHagar / plexcsharp

An open source Plex Media Server C# SDK
MIT License
11 stars 2 forks source link

Missing `Accept: application/json` header? #10

Open dstaley opened 5 days ago

dstaley commented 5 days ago

Forgive me if I'm missing it, but I don't think this SDK is setting the Accept: application/json header like the other SDKs?

JavaScript Go

C#

Unhandled exception: Unknown content type received: Status 200
<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="1">
<Server name="Euporie" host="192.168.50.187" address="192.168.50.187" port="32400" machineIdentifier="..." version="1.41.2.9134-3391644e0" />
</MediaContainer>
JasonLandbridge commented 5 days ago

Yes, unfortunately you're correct and this seems to be an unresolved issue in how the CSharp SDK is generated.

I worked around this issue by creating my own client, add the headers and then inject that into the PlexAPI class:

var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var plexApi =  new PlexAPI( client: client);

I would say that 99% of all endpoints use json responses. If you need an implementation example you can look here: https://github.com/PlexRipper/PlexRipper/blob/dev/src/PlexApi/PlexApiWrapper.cs