| 869 | } |
| 870 | |
| 871 | post(opts, callback = () => {}) { |
| 872 | // 如果指定了请求体, 但没指定`Content-Type`, 则自动生成 |
| 873 | if (opts.body && opts.headers && !opts.headers['Content-Type']) { |
| 874 | opts.headers['Content-Type'] = 'application/x-www-form-urlencoded' |
| 875 | } |
| 876 | if (opts.headers) delete opts.headers['Content-Length'] |
| 877 | if (this.isSurge() || this.isLoon()) { |
| 878 | if (this.isSurge() && this.isNeedRewrite) { |
| 879 | opts.headers = opts.headers || {} |
| 880 | Object.assign(opts.headers, { |
| 881 | 'X-Surge-Skip-Scripting': false |
| 882 | }) |
| 883 | } |
| 884 | $httpClient.post(opts, (err, resp, body) => { |
| 885 | if (!err && resp) { |
| 886 | resp.body = body |
| 887 | resp.statusCode = resp.status |
| 888 | } |
| 889 | callback(err, resp, body) |
| 890 | }) |
| 891 | } else if (this.isQuanX()) { |
| 892 | opts.method = 'POST' |
| 893 | if (this.isNeedRewrite) { |
| 894 | opts.opts = opts.opts || {} |
| 895 | Object.assign(opts.opts, { |
| 896 | hints: false |
| 897 | }) |
| 898 | } |
| 899 | $task.fetch(opts).then( |
| 900 | (resp) => { |
| 901 | const { |
| 902 | statusCode: status, |
| 903 | statusCode, |
| 904 | headers, |
| 905 | body |
| 906 | } = resp |
| 907 | callback(null, { |
| 908 | status, |
| 909 | statusCode, |
| 910 | headers, |
| 911 | body |
| 912 | }, body) |
| 913 | }, |
| 914 | (err) => callback(err) |
| 915 | ) |
| 916 | } else if (this.isNode()) { |
| 917 | this.initGotEnv(opts) |
| 918 | const { |
| 919 | url, |
| 920 | ..._opts |
| 921 | } = opts |
| 922 | this.got.post(url, _opts).then( |
| 923 | (resp) => { |
| 924 | const { |
| 925 | statusCode: status, |
| 926 | statusCode, |
| 927 | headers, |
| 928 | body |