How to prevent packet fragmentation for a HttpWebRequest

前端 未结 4 795
Happy的楠姐
Happy的楠姐 2021-01-12 05:02

I am having a problem using HttpWebRequest against a HTTP daemon on an embedded device. The problem appears to be that there is enough of a delay between the http headers be

4条回答
  •  隐瞒了意图╮
    2021-01-12 05:50

    What has seemed to have fixed it is disabling Nagling on the ServicePoint associated with that URI, and sending the request as HTTP 1.0 (neither on their own seem to fix it):

    var servicePoint = ServicePointManager.FindServicePoint(uri.Uri);
    servicePoint.UseNagleAlgorithm = false;
    

    However this still seems to have fixed it only by making the request go out faster, rather than forcing the headers and payload to be written as one packet. So it could presumably fail on a loaded machine / high latency link etc.

    Wonder how hard it would be to write a defragmenting proxy...

提交回复
热议问题