示例
http 1.6.0: Test code that calls an HTTP API with package:http using MockClient, with no network, and see what the client actually sends and decodes
已验证示例 — pub http 1.6.0: Test code that calls an HTTP API with package:http using MockClient, with no network, and see what the client actually sends and…
sha256:ed3c594714b9ed323ec4da016bdf6f9e47b615cc78872cab62588dd0532e98b7
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 2
- 构建过它的签名密钥
- 2
声明的环境
dart 3 linux x64 dart 3 dart pub
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| dart 3 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · pub@1 |
2026-08-14 |
| dart 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · pub@1 |
2026-08-18 |
案例
HOW- 目标
- Test code that calls an HTTP API with package:http using MockClient, with no network, and see what the client actually sends and decodes
- 符号
-
- MockClient
- Client.get
- Client.post
- Client.read
- Response.body
- Response.bodyBytes
- Request.bodyFields
- MultipartRequest
- ClientException
- 环境
- dart 3
- 创建时间
- 2026-08-14T09:40:43Z
契约
- assert the MockClient handler receives the finalized request the client built, with its url and query, headers that look up case-insensitively but keep the case you wrote, and an empty GET body
- assert the handler argument is a rebuilt plain Request rather than your object, so a MultipartRequest arrives flattened to its encoded body and boundary header, and the request you sent comes back finalized
- assert a 404 does not throw from get: the Future completes, the error body decodes like any payload, and only statusCode and reasonPhrase report it
- assert read and readBytes are the exception and throw a ClientException at status 400 and above, with the server's error body no longer reachable, while 399 is read back as a body
- assert response.body decodes application/json without a charset as utf8 but falls back to latin1 for text/plain, text/html, application/xml, a vendor +json subtype and a missing content-type, while bodyBytes stays raw
- assert a Map body is form-encoded as application/x-www-form-urlencoded with percent-encoded utf8 and no charset parameter appended
- assert a declared JSON content-type stays exactly application/json with utf8 bytes on the wire, while an undeclared String body is announced as text/plain; charset=utf-8 and a declared application/xml gains charset=utf-8
- assert passing a Map under a JSON content-type throws StateError from Request.bodyFields instead of silently mis-encoding
- assert a ClientException thrown by the handler propagates unwrapped with its message and uri, and any other exception type propagates with its own type
文件
- csx.json
- lib/users.dart
- pubspec.lock
- pubspec.yaml
- test/contract_test.dart