-
Hi, everyone. I ran into a http issue when I try to post some data to a server using .net 4.5. I can post successfully via Postman but in .net I always get 502 error. I assume it is the server's problem but I can do nothing to the server. The I found the main difference between the requests sended by Postman and .net 4.5 is that the body is in a seperated segment in .net. Then I tried .net 6.0, it behaves like Postman and can post successfully. However I can't migrate my project to .net 6.0 now. So is there any way to control the segmentation in .net 4.5? This is the test code both in .net 4.5 and .net 6.0:
Note that I tested those code in C# Interactive which should use 4.8 in latest windows 10 and it makes no difference. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
@dotnet/ncl Note that .NET Framework 4.5 should be out of support now. Using 4.8 which is an in-place update is suggested. |
Beta Was this translation helpful? Give feedback.
-
I don't think you can influence this in any way. This seems to be a property of how .NET Core by default uses managed implementation of Http ( |
Beta Was this translation helpful? Give feedback.
-
This is really fragile behavior for the server to rely on. With YARP for example, you would get the same behavior as if you had upgraded the client to 6.0. |
Beta Was this translation helpful? Give feedback.
-
As mentioned above, all the options are fragile and there is no good way how to impact this reliably. You can also try to set |
Beta Was this translation helpful? Give feedback.
-
Thank you very much. Fanally I didn't find any way to influence the segmentation. So I write a simple proxy tool using .net 6.0 which solves the problem. |
Beta Was this translation helpful? Give feedback.
This is really fragile behavior for the server to rely on.
If you can't upgrade to .NET 6, you can consider putting a reverse proxy between your client and server. The client will still send the request in multiple TCP segments, but the proxy can buffer them for you.
With YARP for example, you would get the same behavior as if you had upgraded the client to 6.0.
We will send up to 4 KB of headers+content down to the
Socket
in 1 call, but there is no guarantee of how that will be split up on the transport layer. If your headers+content are always small, odds are they will be grouped together.