使用 Asp.Net Core 进行反向代理
我编写了一个中间件,它捕获请求并根据要求发送 HttpRequest (在 HttpClient 的帮助下)并将所有 HTTP 响应部分(标头、正文)从结果复制到我的上下文。但是当我得到
传输编码:分块
标头中分块,响应未正确返回到最终用户。 如何将完全相同的响应复制到我的上下文中并正确继续?
private void CopyFromTargetResponseHeaders(HttpContext context, HttpResponseMessage responseMessage)
{
foreach (var header in responseMessage.Headers)
{
context.Response.Headers[header.Key] = header.Value.ToArray();
}
foreach (var header in responseMessage.Content.Headers)
{
context.Response.Headers[header.Key] = header.Value.ToArray();
}
}
I have written a middleware that catches the request and based on the requirement it sends HttpRequest (with the help of HttpClient) and copies all the HTTP response parts(headers, body) from the result to my context. But when I get
transfer-encoding: chunked
in the header, the response is not returning to the end-user properly.
How can I copy the exact same response to my context and continue correctly?
private void CopyFromTargetResponseHeaders(HttpContext context, HttpResponseMessage responseMessage)
{
foreach (var header in responseMessage.Headers)
{
context.Response.Headers[header.Key] = header.Value.ToArray();
}
foreach (var header in responseMessage.Content.Headers)
{
context.Response.Headers[header.Key] = header.Value.ToArray();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论