freezy 2 Posted March 16, 2017 Share Posted March 16, 2017 I'm having a go at implementing a server plugin. My plugin talks to a REST API. Given there is IHttpClient and IJsonSerializer I thought this would be easy. However, I can't find any documentation of any of those interfaces. IHttpClient can serialize response data from a stream into an object, so I would expect the same for the request data, i.e. posting data through the serializer. But IHttpClient only seems to accept dictionaries as data for all Post overloads. Am I missing something? Do I really have to set property by property for every request? What if I have nested properties? Also, I can't seem to find an actual implementation of IHttpClient. Given I have not found any documentation about the interface, this would be important for lots of reasons, namely to see how cookie handling works, but also redirection and other things. Any links to documentation or source code of the above mentioned would be appreciated. Cheers. -freezy. Link to comment Share on other sites More sharing options...
Luke 37180 Posted March 16, 2017 Share Posted March 16, 2017 Hi, there's a method to set the post content as a string. just make sure to set the content type as well. Link to comment Share on other sites More sharing options...
freezy 2 Posted March 16, 2017 Author Share Posted March 16, 2017 Which one? That's all I'm seeing: Task<Stream> Post(string url, Dictionary<string, string> postData, SemaphoreSlim resourcePool, CancellationToken cancellationToken); Task<Stream> Post(string url, Dictionary<string, string> postData, CancellationToken cancellationToken); Task<Stream> Post(HttpRequestOptions options, Dictionary<string, string> postData); Task<HttpResponseInfo> Post(HttpRequestOptions options); I don't see anything data-related in HttpRequestOptions, and all the other overloads take in dictionaries. This is MediaBrowser.Common.Net.IHttpClient. Link to comment Share on other sites More sharing options...
Luke 37180 Posted March 16, 2017 Share Posted March 16, 2017 There is a method on the HttpRequestOptions, and then you can use the lower level SendAsync method. Link to comment Share on other sites More sharing options...
freezy 2 Posted March 16, 2017 Author Share Posted March 16, 2017 Ah right, there is string RequestContent in HttpRequestOptions. Could I also just use Post(HttpRequestOptions options) then? Link to comment Share on other sites More sharing options...
Luke 37180 Posted March 16, 2017 Share Posted March 16, 2017 Yes. Link to comment Share on other sites More sharing options...
freezy 2 Posted March 16, 2017 Author Share Posted March 16, 2017 Thanks! So for the cookies I suppose that IHttpClient doesn't automatically persist cookies for a given domain and I'll need to set them for every request? If so, is there a way to easily cache them somewhere? For the redirections similar question: If there is a HTTP 301/302 received, does IHttpClient automatically follow or do I need to do this manually? Link to comment Share on other sites More sharing options...
Luke 37180 Posted March 16, 2017 Share Posted March 16, 2017 It is a wrapper over HttpWebRequest. I am not sure of the answers to those questions so you will probably need to research that. I am guessing the redirect will be followed though. Link to comment Share on other sites More sharing options...
freezy 2 Posted March 16, 2017 Author Share Posted March 16, 2017 Alright, thanks Luke! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now