forked from shamblett/coap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_blockwise.dart
44 lines (36 loc) · 1.26 KB
/
post_blockwise.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// ignore_for_file: avoid_print
/*
* Package : Coap
* Author : S. Hamblett <[email protected]>
* Date : 06/06/2018
* Copyright : S.Hamblett
*
* A request demonstrating a blockwise (block1) post
*/
import 'dart:async';
import 'package:coap/coap.dart';
import 'config/coap_config.dart';
import 'utils.dart';
FutureOr<void> main() async {
final conf = CoapConfig();
final baseUri = Uri(scheme: 'coap', host: 'coap.me', port: conf.defaultPort);
final client = CoapClient(baseUri, config: conf);
final opt = UriQueryOption(
'${LinkFormatParameter.title.short}=This is an SJH Post request',
);
// Random large payload
final payload = getRandomString(length: 2000);
try {
print('Sending post /large-create to ${baseUri.host}');
var response = await client
.post(Uri(path: 'large-create'), payload: payload, options: [opt]);
print('/large-create response status: ${response.statusCodeString}');
print('Sending get /large-create to ${baseUri.host}');
response = await client.get(Uri(path: 'large-create'));
print('/large-create response:\n${response.payloadString}');
print('E-Tags : ${response.etags.join(',')}');
} on Exception catch (e) {
print('CoAP encountered an exception: $e');
}
client.close();
}