Pārlūkot izejas kodu

修复作为子站点获取访问Gateway错误问题

linhong 3 gadi atpakaļ
vecāks
revīzija
e9bf3ea8e9

+ 7 - 34
Controllers/L1SvrController.cs

@@ -14,6 +14,7 @@ using System.IO;
 using System.Text;
 using Newtonsoft.Json.Linq;
 using LJProxy.Services;
+using Microsoft.AspNetCore.Http.Extensions;
 
 namespace LJProxy.Controllers
 {
@@ -39,40 +40,12 @@ namespace LJProxy.Controllers
             {
                 requestBody = await reader.ReadToEndAsync();
             }
-            //var files = Request.Form.Files;
-            //if (files != null && files.Count > 0)
-            //{
-            //    UploadFilesRequest requestObj = new UploadFilesRequest();
-
-            //    foreach (var file in files)
-            //    {
-            //        var path = $"{AppDomain.CurrentDomain.BaseDirectory}test\\{file.FileName}";
-            //        byte[] buffer = new byte[2048];
-            //        using (var fs = file.OpenReadStream())
-            //        {
-            //            using (var fsn = System.IO.File.Create(path))
-            //            {
-            //                while (true)
-            //                {
-            //                    var size = fs.Read(buffer, 0, buffer.Length);
-            //                    if (size == 0)
-            //                    {
-            //                        break;
-            //                    }
-            //                    fsn.Write(buffer, 0, size);
-            //                }
-            //                fsn.Flush();
-            //            }
-            //        }
-            //    }
-            //}
-            var uriBuilder = new UriBuilder
-            {
-                Scheme = Request.Scheme,
-                Host = Request.Host.Host,
-                Port = Request.Host.Port.GetValueOrDefault(80),
-            };
-            var gateway= uriBuilder.Uri;
+            var url = Request.GetDisplayUrl();
+            var pathStart = "/api/l1svr/svr/";
+            var idx = url.IndexOf(pathStart, StringComparison.OrdinalIgnoreCase);
+            string gateway = string.Empty;
+            if (idx > 0)
+                gateway = url.Substring(0, idx + 1);
             if (!string.IsNullOrEmpty(requestBody))
             {
                 var reqObj = JObject.Parse(requestBody);

+ 3 - 1
Controllers/TestController.cs

@@ -1,4 +1,5 @@
-using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Http.Extensions;
+using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
 using System.IO;
@@ -35,5 +36,6 @@ namespace LJProxy.Controllers
             return Content(result, "application/json");
 
         }
+
     }
 }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
Properties/PublishProfiles/FolderProfile.pubxml.user


+ 1 - 1
Properties/launchSettings.json

@@ -4,7 +4,7 @@
     "anonymousAuthentication": true,
     "iisExpress": {
       "applicationUrl": "http://127.0.0.1:58966",
-      "sslPort": 0
+      "sslPort": 44390
     }
   },
   "$schema": "http://json.schemastore.org/launchsettings.json",