将Microsoft.AspNetCore.Http.HttpRequest转换为HttpRequestMessage [英] Convert Microsoft.AspNetCore.Http.HttpRequest to HttpRequestMessage

查看:1126
本文介绍了将Microsoft.AspNetCore.Http.HttpRequest转换为HttpRequestMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 Microsoft.AspNetCore.Http.HttpRequest 从AspNetCore上下文转换为 HttpRequestMessage ,以传递给HttpClient.有没有简单的方法可以做到这一点?否则任何实现此建议的提示都会很有帮助.

I need to convert Microsoft.AspNetCore.Http.HttpRequest from an AspNetCore context to an HttpRequestMessage to pass to an HttpClient. Is there a simple way of achieve this? Or any hint to implement this would be very helpful.

更新 我想将请求转换为消息,但是我想更改目标URL,我只想将请求重定向到另一台服务器.

Update I want to convert the request into a message but I want to change the target url, I want just to redirect the request into another server.

推荐答案

尝试 Web API兼容性Shim

Try Web API Compatibility Shim

HttpRequestMessageFeature hreqmf = new HttpRequestMessageFeature(context);
HttpRequestMessage httpRequestMessage = hreqmf.HttpRequestMessage;

或者您可能会受到 Microsoft.AspNetCore.Proxy

Or you could get inspired by Microsoft.AspNetCore.Proxy

这些扩展添加到httpContext可能会派上用场.

These extensions to httpContext may come in handy.

这篇关于将Microsoft.AspNetCore.Http.HttpRequest转换为HttpRequestMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆