6.41HttpContext 转发扩展方法
创建于 2026 年 8 月 17 日约 1 分钟读完
框架为 HttpContext 提供了多种扩展方法,旨在满足各种场景下的 HTTP 请求转发需求。
// 返回 HttpResponseMessage 对象httpContext.Forward(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置httpContext.Forward(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsync(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置await httpContext.ForwardAsync(httpMethod, requestUri, configure, completionOption, forwardOptions);// 返回 HttpRemoteResult<T>httpContext.Forward<T>(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置httpContext.Forward<T>(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsync<T>(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置await httpContext.ForwardAsync<T>(httpMethod, requestUri, configure, completionOption, forwardOptions);// 返回目标 T 类型httpContext.ForwardAs<T>(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置httpContext.ForwardAs<T>(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsAsync<T>(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置await httpContext.ForwardAsAsync<T>(httpMethod, requestUri, configure, completionOption, forwardOptions);// 返回字符串类型httpContext.ForwardAsString(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置httpContext.ForwardAsString(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsStringAsync(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置await httpContext.ForwardAsStringAsync(httpMethod, requestUri, configure, completionOption, forwardOptions);// 返回字节数组类型httpContext.ForwardAsByteArray(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置httpContext.ForwardAsByteArray(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsByteArrayAsync(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置await httpContext.ForwardAsByteArrayAsync(httpMethod, requestUri, configure, completionOption, forwardOptions);// 返回 Stream 类型httpContext.ForwardAsStream(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置httpContext.ForwardAsStream(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsStreamAsync(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置await httpContext.ForwardAsStreamAsync(httpMethod, requestUri, configure, completionOption, forwardOptions);// 返回 IActionResult 类型httpContext.ForwardAsResult(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置httpContext.ForwardAsResult(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsResultAsync(requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置await httpContext.ForwardAsResultAsync(httpMethod, requestUri, configure, completionOption, forwardOptions);// 返回 object 类型httpContext.ForwardAs(resultType, requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置httpContext.ForwardAs(resultType, httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsAsync(resultType, requestUri, configure, completionOption, forwardOptions); // 自动获取 HttpContext.Request.Method 方法进行设置await httpContext.ForwardAsAsync(resultType, httpMethod, requestUri, configure, completionOption, forwardOptions);