简体   繁体   English

.Net Core 3.1 - HTTP 请求 - 分别发送标头和正文

[英].Net Core 3.1 - HTTP request - Send header and body separately

I'm using legacy server, which requires that header and body in HTTP POST requests are sent separately.我正在使用旧服务器,它要求 HTTP POST 请求中的标头和正文分开发送。 I suppose this is achieved with 'Expect: 100-continue', which is present in legacy's client message header.我想这是通过“Expect: 100-continue”实现的,它存在于旧版的客户端消息标头中。

I'm writing new client with use of Net Core 3.1, which seems doesn't have support of Expect100Continue in HttpWebRequest class (According to: https://github.com/dotnet/runtime/issues/25881 )我正在使用 Net Core 3.1 编写新客户端,它似乎不支持 HttpWebRequest 类中的 Expect100Continue(根据: https : //github.com/dotnet/runtime/issues/25881

Is there any possibility, to send HTTP request with Net Core 3.1 with separated body and header?有没有可能,用 Net Core 3.1 发送 HTTP 请求,正文和标头分开?

Quick solution was turning off net core's HTTP handler with快速解决方案是关闭 net core 的 HTTP 处理程序

AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);

After this switch, handler from .net framework is used.在此切换后,将使用 .net 框架中的处理程序。 It looks like that SocketsHttpHandler (at least with combination with HttpWebRequest) doesn't support separated headers and bodies, even when HTTP 1.0 is used.看起来 SocketsHttpHandler (至少与 HttpWebRequest 结合使用)不支持分离的标头和正文,即使使用 HTTP 1.0 也是如此。

https://docs.microsoft.com/en-us/dotnet/api/system.appcontext.setswitch?view=netcore-3.1 https://docs.microsoft.com/en-us/dotnet/api/system.appcontext.setswitch?view=netcore-3.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 中间件异常后获取请求正文。 .NET 核心 3.1 - Get request body after exception in middleware. .NET Core 3.1 使用 .Net Core 3.1 的 POST 请求和 Power Automate 的 HTTP 请求 - POST Request using .Net Core 3.1 and HTTP Request of Power Automate 将包含带有连字符的 Header 属性的请求绑定到 .Net Core 3.1 API - Bind request containing Header property with Hyphens to .Net Core 3.1 API .net 核心对 http GET 和发送主体的错误请求 - .net core bad request for http GET and sending body 在 .Net Core 3.0 中间件中使用自定义标头填充 HTTP 请求标头 - Populate HTTP request headers with custom header in .Net Core 3.0 middleware 如何在 ASP .NET Core MVC 中将 Cookie 添加到 http 请求标头 - How add Cookies to http request header in ASP .NET Core MVC 从.NET Core中另一个IP地址发送HTTP请求 - Send a HTTP request from another IP address in .NET Core 在 .NET Core 3.1 API 中验证 http 请求的好方法是什么? - What is good approach to validate http request in .NET Core 3.1 API's? 如何在asp.net core(Kestrel)中记录http请求消息(非正文)和响应消息(非正文) - how to log http request message(not body) and response message(not body) in asp.net core(Kestrel) 在 .net core 中通过 http 发出 Grpc 请求时会产生以下异常。 我正在使用 .net 核心 3.1 - When making Grpc request over http in .net core creates following exception. I am using .net core 3.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM