-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.dart
34 lines (28 loc) · 958 Bytes
/
http.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
import 'dart:async';
import 'dart:convert';
import 'package:socks5_io/socks5_io.dart';
import 'package:socks5_io/src/utils/socket_like.dart';
main() async {
final List<dynamic> proxy = ["127.0.0.1", 7890];
final List<dynamic> target = ["example.org", 80];
final dialer = Socks5ClientDialer(proxy[0], proxy[1]);
dialer.connect(target[0], target[1]).then((SocketLike socks5) {
final completer = Completer();
// handle remote server response
socks5.getReader().listen((buffer) {
completer.complete(ascii.decode(buffer));
});
// send request (non-blocking)
socks5.getWriter().add(ascii.encode([
"GET / HTTP/1.1",
"Host: example.org:80",
"User-Agent: curl/7.79.1",
"Accept: */*",
"\r\n",
].join("\r\n")));
completer.future.then((responseText) {
print(responseText);
socks5.close();
});
}).catchError((err) {/* handle connect error */});
}