Table of Contents

Interface IHttpResponse

Namespace
CurlUnity.Http

HTTP 响应。由 SendAsync(IHttpRequest, CancellationToken) 在成功拿到响应时返回。

public interface IHttpResponse : IDisposable
Inherited Members

Remarks

只有成功路径才返回本对象。网络/TLS/超时等失败抛 CurlHttpException, 取消抛 OperationCanceledException;详见 CurlHttpException 的文档。HTTP 4xx/5xx 不算失败,通过 StatusCode 判断。

持有底层 libcurl easy handle;必须 Dispose()(或 using),否则 handle 会泄漏。在 Dispose 之前 ContentType / Headers 等 属性都能反复读取。Dispose 后依赖 curl_easy_getinfo 的懒加载属性 (Version / ContentType / ContentLength / EffectiveUrl / RedirectCount / Headers) 会返回默认值或 null;已缓存到托管字段的 StatusCode / Body 仍返回原值。

Properties

Body

响应体。流式模式(设置 OnDataReceived)下为 null, 数据已通过回调逐块交付。若请求开启了 AutoDecompressResponse, 这里是解压后的明文。

ContentLength

Content-Length,未知时为 -1。

ContentType

Content-Type(如 "application/json; charset=utf-8"),无则 null。

EffectiveUrl

重定向后的最终 URL。无重定向时等于请求 URL。

Headers

所有响应头。key 为小写 header name,value 为该 header 的所有值。 仅在请求设置 EnableResponseHeaders=true 时可用,否则返回 null。

IsDisposed

底层 easy handle 是否已释放。

RedirectCount

重定向次数。

StatusCode

HTTP 状态码(含 4xx / 5xx)。

Version

实际使用的 HTTP 协议版本。可能与请求偏好不同(例如启用代理会从 H3 降到 H2)。