فهرست منبع

Make Http Request supports application/json

Signed-off-by: Jack Cherng <jfcherng@gmail.com>
Jack Cherng 5 سال پیش
والد
کامیت
7ba4aca421
1فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 5 1
      Protocols/Http/Request.php

+ 5 - 1
Protocols/Http/Request.php

@@ -464,7 +464,11 @@ class Request
             $this->parseUploadFiles($http_post_boundary);
             return;
         }
-        \parse_str($body_buffer, $this->_data['post']);
+        if (\preg_match('/\bjson\b/i', $content_type)) {
+            $this->_data['post'] = (array) json_decode($body_buffer, true);
+        } else {
+            \parse_str($body_buffer, $this->_data['post']);
+        }
         if ($cacheable) {
             static::$_postCache[$body_buffer] = $this->_data['post'];
             if (\count(static::$_postCache) > 256) {