-
Notifications
You must be signed in to change notification settings - Fork 352
/
http_request_bin.nim
36 lines (24 loc) · 1.27 KB
/
http_request_bin.nim
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
#[
Author: Marcello Salvati, Twitter: @byt3bl33d3r
License: BSD 3-Clause
You have 4 options (that I'm aware of at the time of writing) to make an HTTP request with Nim from Windows:
- Use Nim's builtin httpclient library (which has it's own HTTP implementation and uses raw sockets)
- Warning: httpclient module currently doesn't perform cert validation, see https://nim-lang.org/docs/httpclient.html#sslslashtls-support
- Use the WinHttp Com Object (through Winim) apperently that's a thing. Either didn't know about it or forgot about it.
- Use Winim's wininet or winhttp modules which call their respective Windows API's
- Use the IE Com Object (through Winim)
The first two of those are by far the easiest.
References:
- https://github.com/khchen/winim/blob/master/examples/com/InternetExplorer_Application.nim
- https://github.com/khchen/winim/blob/master/examples/com/WinHttp_WinHttpRequest.nim
]#
import winim/com
import httpclient
echo "[*] Using httpclient"
var client = newHttpClient()
echo client.getContent("https://ifconfig.me")
echo "[*] Using the WinHTTP.WinHttpRequest COM Object"
var obj = CreateObject("WinHttp.WinHttpRequest.5.1")
obj.open("get", "https://ifconfig.me")
obj.send()
echo obj.responseText