Browse Source

debug for content

stanley-king 4 years ago
parent
commit
b6d407f819
2 changed files with 28 additions and 10 deletions
  1. 24 6
      helper/request_helper.php
  2. 4 4
      test/TestRefill.php

+ 24 - 6
helper/request_helper.php

@@ -254,6 +254,12 @@ class request_helper
         }
     }
 
+    static function start_with ($string, $startString)
+    {
+        $len = strlen($startString);
+        return (substr($string, 0, $len) === $startString);
+    }
+
     static public function fill_param()
     {
         $method = strtolower(request_helper::method());
@@ -265,14 +271,26 @@ class request_helper
             $_SERVER['post_content'] = $content;
         }
 
-        $content_type = strtolower(self::content_type());
-        Log::record("type = {$content_type}, content={$content}",Log::DEBUG);
+        if(!empty($content))
+        {
+            $content_type = strtolower(self::content_type());
+            Log::record("type = {$content_type}, content={$content}",Log::DEBUG);
 
-//        $formtypes = ['application/x-www-form-urlencoded','text/xml','text/html'];
+            $checker = function ($stype)
+            {
+                $formtypes = ['application/x-www-form-urlencoded','text/xml','text/html','multipart/form-data'];
+                foreach ($formtypes as $type) {
+                    if(self::start_with($stype,$type)) {
+                        return true;
+                    }
+                }
+                return false;
+            };
 
-//        if(empty($content_type) || in_array($content_type,$formtypes)) {
-            self::parse_formurl($content,$method);
-//        }
+            if(empty($content_type) || $checker($content_type)) {
+                self::parse_formurl($content,$method);
+            }
+        }
     }
 
     static private function parse_formurl($squery,$method)

+ 4 - 4
test/TestRefill.php

@@ -346,21 +346,21 @@ class TestRefill extends TestCase
     private function body($params)
     {
         ksort($params);
-        $stringToBeSigned = "";
+        $body = "";
         $i = 0;
         foreach ($params as $k => $v)
         {
             if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1))
             {
                 if ($i == 0) {
-                    $stringToBeSigned .= "{$k}" . "=" . urlencode($v);
+                    $body .= "{$k}" . "=" . urlencode($v);
                 } else {
-                    $stringToBeSigned .= "&" . "{$k}" . "=" . urlencode($v);
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
                 }
                 $i++;
             }
         }
-        return $stringToBeSigned;
+        return $body;
     }
 
     private function checkEmpty($value)