当我调用 URLSessionTask task.cancel() 时会发生什么?

What happens when I call URLSessionTask's task.cancel()?

当我们取消请求时,reference for this method only says what happens locally on the client, and says nothing about what it potentially sends to the server. Apparently, our server has some challenges with receiving a lot of status code 499 来自我们,但我找不到任何关于 URLSession 如何处理取消的信息。是否有基于 HTTP 协议的标准取消消息?

客户端不发送499,状态码是单向的。相反,客户端关闭网络连接。服务器在其日志中将断开连接记录为 499 状态代码。

如果服务器是 HTTP/2 或更高版本,客户端可以发送 END_STREAM 或 RST_STREAM 消息来取消单个请求而不取消同一连接上的其他请求,或者它可能只是断开连接。无论哪种方式,您可能只会在日志中看到 499。几乎没有理由关心连接是否被丢弃或取消。