作者:阿魏空荡荡 | 来源:互联网 | 2023-08-20 14:45
IvegotapiwrittenwithWepApi2tightlycoupledwithmainwebsite.Ivedecidedtodecoupleitt
I've got api written with WepApi 2 tightly coupled with main web site. I've decided to decouple it to another web app to keep things more isolated.
我已经用WepApi 2编写了api,它与主网站紧密耦合。我决定将它与另一个web应用程序解耦,以使其更加独立。
I've followed such steps:
我跟着这些步骤:
- Extract all the API controllers to another project
- 将所有API控制器提取到另一个项目中
Creat attribute to redirect all the users currently using our old URL to the new one. For such reasons I've used 307 status code because we should keep user's request's verb and request payload.
Creat属性将当前使用旧URL的所有用户重定向到新URL。出于这种原因,我使用了307状态码,因为我们应该保留用户请求的谓词和请求负载。
var respOnse= request.CreateResponse(HttpStatusCode.TemporaryRedirect); //307
response.Headers.Location = new Uri($"{appConfig.ApiAppDomain}" + "/" + request.RequestUri.AbsolutePath + request.RequestUri.Query);
return response;
In common it works nice. Client got 307 and then follows to the URL in Location
header.
通常它工作得很好。客户端获得307,然后跟踪到位置头中的URL。
The problem is here: the main web app is https
and the new api is http
. When I'm using postman it behave strange and do replace the POST
request with GET
request with all request's body cutting. Not good at all and strange because 307
doesn't allow to change the method and the payload.
问题在于:主要的web应用程序是https,而新的api是http。当我在使用postman时,它的行为很奇怪,并且用所有请求的body cut替换POST请求。不太好,很奇怪,因为307不允许改变方法和有效载荷。
So here are the couple of questions:
下面是几个问题:
- What is the best way to handle this https -> http redirection?
- 处理这个https -> http重定向的最佳方式是什么?
- Whether it is good solution at all or not?
- 它到底是不是一个好的解决方案?
- What is the best solution to silently move our users to new api url?
- 无声地将用户移动到新的api url的最佳解决方案是什么?
1 个解决方案