Переглянути джерело

优化base_request支持传data

hjdhnx 2 місяців тому
батько
коміт
c3b88479bb
2 змінених файлів з 12 додано та 7 видалено
  1. 4 2
      app/t4/files/drpy_js/老白故事[听].js
  2. 8 5
      app/utils/vod_tool.py

+ 4 - 2
app/t4/files/drpy_js/老白故事[听].js

@@ -262,7 +262,8 @@ var rule = {
         headers['Content-Type'] = 'application/x-www-form-urlencoded';
         let html = post(appData.api_url, {
             headers: headers,
-            body: post_data,
+            // body: post_data,
+            data: post_obj,
         });
         let content = JSON.parse(html);
         var datas = content.data;
@@ -306,7 +307,8 @@ var rule = {
         headers['Content-Type'] = 'application/x-www-form-urlencoded';
         let html = post(appData.api_url, {
             headers: headers,
-            body: post_data,
+            // body: post_data,
+            data: post_obj,
         });
         let content = JSON.parse(html);
         var datas = content.data;

+ 8 - 5
app/utils/vod_tool.py

@@ -83,17 +83,20 @@ def base_request(_url, _object, _js_type=0, cloudfare=False):
 
     elif not body and data and method != 'get':
         content_type_keys = [key for key in headers if key.lower() == 'content-type']
-        content_type = 'application/json'
+        default_type = 'application/json'
+        content_type = default_type
         if content_type_keys:
             content_type_key = content_type_keys[-1]
             old_content_type = headers[content_type_key]
-            if content_type not in old_content_type:
-                headers[content_type_key] = content_type
+            # if content_type not in old_content_type:
+            #     headers[content_type_key] = content_type
+            content_type = old_content_type
         else:
-            headers['Content-Type'] = content_type
+            headers['Content-Type'] = default_type
 
-        if isinstance(data, dict):
+        if isinstance(data, dict) and default_type in content_type:
             data = ujson.dumps(data, ensure_ascii=False)
+
     buffer = _object.get('buffer') or 1
     redirect = False if _object.get('redirect') == 0 or _object.get('redirect') == False else True
     withHeaders = bool(_object.get('withHeaders') or False)