- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
将数据写入 Web 服务器时,我的测试显示 HttpWebRequest.ReadWriteTimeout 被忽略,与 MSDN spec 相反.例如,如果我将 ReadWriteTimeout 设置为 1(=1 毫秒),调用 myRequestStream.Write() 传递一个需要 10 秒传输的缓冲区,它传输成功并且永远不会使用 .NET 3.5 SP1 超时。在 Mono 2.6 上运行的相同测试如预期的那样立即超时。有什么问题吗?
最佳答案
似乎存在一个错误,当在 BeginGetRequestStream() 返回给您的 Stream 实例上设置写入超时时,它不会向下传播到 native 套接字。我将提交错误以确保此问题在 .NET Framework 的 future 版本中得到纠正。
这是一个解决方法。
private static void SetRequestStreamWriteTimeout(Stream requestStream, int timeout)
{
// Work around a framework bug where the request stream write timeout doesn't make it
// to the socket. The "m_Chunked" field indicates we are performing chunked reads. Since
// this stream is being used for writes, the value of this field is irrelevant except
// that setting it to true causes the Eof property on the ConnectStream object to evaluate
// to false. The code responsible for setting the socket option short-circuits when it
// sees Eof is true, and does not set the flag. If Eof is false, the write timeout
// propagates to the native socket correctly.
if (!s_requestStreamWriteTimeoutWorkaroundFailed)
{
try
{
Type connectStreamType = requestStream.GetType();
FieldInfo fieldInfo = connectStreamType.GetField("m_Chunked", BindingFlags.NonPublic | BindingFlags.Instance);
fieldInfo.SetValue(requestStream, true);
}
catch (Exception)
{
s_requestStreamWriteTimeoutWorkaroundFailed = true;
}
}
requestStream.WriteTimeout = timeout;
}
private static bool s_requestStreamWriteTimeoutWorkaroundFailed;
关于HttpWebRequest ReadWriteTimeout 在 .NET 中被忽略;在单声道工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2679192/
我最近从 HttpWebRequest 切换到 HttpClient ,似乎 HttpClient 只有正常的超时属性。我找不到任何代表读/写超时的属性。我在 HttpClient 或 HttpCli
将数据写入 Web 服务器时,我的测试显示 HttpWebRequest.ReadWriteTimeout 被忽略,与 MSDN spec 相反.例如,如果我将 ReadWriteTimeout 设置
HttpWebRequests 的 ReadWriteTimeout 似乎默认为 5 分钟。 有这么高的原因吗?我试图将 API 调用的超时设置为 10 秒,但它旋转了超过 2 分钟。 当我将此设置为
我相信我了解 HttpWebRequest.Timeout 和 HttpWebRequest.ReadWriteTimeout 之间的实际区别。但是,我希望进一步清楚这两个超时之间的区别,包括这些值相
我是一名优秀的程序员,十分优秀!