diff --git a/tmhOAuth.php b/tmhOAuth.php index e389331..9360666 100644 --- a/tmhOAuth.php +++ b/tmhOAuth.php @@ -335,7 +335,7 @@ private function prepare_params() { if (isset($this->request_settings['oauth1_params'])) { $oauth1 = &$this->request_settings['oauth1_params']; $doing_oauth1 = true; - $params = array_merge($oauth1, $this->request_settings['params']); + $params = array_merge($oauth1, (is_array($this->request_settings['params']) ? $this->request_settings['params'] : [])); // Remove oauth_signature if present // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.") @@ -646,6 +646,23 @@ private function update_metrics() { return $this->metrics; } + /** + * Determines if the $string is json or not + * + * @param mixed $string + * + * @return bool + */ + private function isJson($string) { + if (!is_string($string)) { + return false; + } + + json_decode($string); + + return (json_last_error() == JSON_ERROR_NONE); + } + /** * Utility function to create the request URL in the requested format. * If a fully-qualified URI is provided, it will be returned. @@ -781,7 +798,11 @@ private function curlit() { $this->request_settings['url'] = $this->request_settings['url'] . '?' . $this->request_settings['querystring']; } elseif ($this->request_settings['method'] == 'POST' || $this->request_settings['method'] == 'PUT') { $postfields = array(); - if (isset($this->request_settings['postfields'])) + + if ($this->isJson($this->request_settings['params'])) { + $postfields = $this->request_settings['params']; + $this->request_settings['headers']['Content-Type'] = 'application/json'; + } elseif (isset($this->request_settings['postfields'])) $postfields = $this->request_settings['postfields']; curl_setopt($c, CURLOPT_POSTFIELDS, $postfields);