File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -212,15 +212,44 @@ public function rescheduleRecording($recordid = -1) {
212212 return false ;
213213 }
214214
215+
216+ /**
217+ * Request something from the backend's HTTP API and return it
218+ * as JSON. This is just syntactic sugar for httpRequest
219+ /**/
220+ public function httpRequestAsJson ($ path , $ args = array (), $ opts = null ) {
221+ if (!$ opts ) {
222+ $ opts = array ();
223+ }
224+
225+ if (!$ opts ['http ' ]) {
226+ $ opts ['http ' ] = array ();
227+ }
228+
229+ if (!$ opts ['http ' ]['method ' ]) {
230+ $ opts ['http ' ]['method ' ] = "GET " ;
231+ }
232+
233+ $ opts ['http ' ]['header ' ] = "Accept: application/json \r\n" ;
234+
235+ return $ this ->httpRequest ($ path , $ args , $ opts );
236+ }
237+
215238/**
216239 * Request something from the backend's HTTP API
217240/**/
218- public function httpRequest ($ path , $ args = array ()) {
241+ public function httpRequest ($ path , $ args = array (), $ opts = null ) {
219242 $ url = "http:// {$ this ->ip }: {$ this ->port_http }/ {$ path }? " ;
220243 foreach ($ args as $ key => $ value ) {
221244 $ url .= urlencode ($ key ).'= ' .urlencode ($ value ).'& ' ;
222245 }
223- return @file_get_contents ($ url );
246+
247+ if (!$ opts ) {
248+ return @file_get_contents ($ url );
249+ } else {
250+ $ context = stream_context_create ($ opts );
251+ return @file_get_contents ($ url , false , $ context );
252+ }
224253 }
225254
226255}
You can’t perform that action at this time.
0 commit comments