zengyicheng 1 tahun lalu
induk
melakukan
bf9a01aabc
1 mengubah file dengan 10 tambahan dan 14 penghapusan
  1. 10 14
      ssti.js

+ 10 - 14
ssti.js

@@ -58,28 +58,24 @@ router.post('/testApi', function(req, res, next) {
     // 创建向后端服务器的请求
     const options = {
         hostname: 'cxcy.ssti.net.cn',
-        port: 80,
+        port: 443,
         path: "/sso/api",
         method: req.method,
         headers: req.headers
     };
 
-    const backendReq = http.request(options, (backendRes) => {
-        console.log(backendRes)
-            // 将后端服务器的响应转发给前端
-        res.writeHead(backendRes.statusCode, backendRes.headers);
-        backendRes.pipe(res);
+    const req = https.request(options, (res) => {
+        // 处理响应
+        res.on('data', (data) => {
+            console.log(data.toString());
+        });
     });
 
-    // 将前端请求的数据转发给后端
-    req.pipe(backendReq);
-
-    // 处理后端请求的错误
-    backendReq.on('error', (error) => {
-        console.error('Error:', error);
-        res.statusCode = 500;
-        res.end('Internal Server Error');
+    req.on('error', (error) => {
+        console.error(error);
     });
+
+    req.end();
 })
 
 //消息与任务接口