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

查看:34
本文介绍了将 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.

推荐答案

Try Web API Compatibility 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天全站免登陆