Skip to content

Commit 0ba84f2

Browse files
committed
Add example to download a file
1 parent fb951e7 commit 0ba84f2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

example/download_file.f90

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
program download_file
2+
! This program demonstrates using a GET request to download a file.
3+
use http, only: response_type, request
4+
use stdlib_io, only: open
5+
implicit none
6+
type(response_type) :: response
7+
integer :: file
8+
9+
response = request('https://avatars.githubusercontent.com/u/53436240')
10+
11+
if (response%ok) then
12+
file = open('fortran-lang.png', 'wb')
13+
write(file) response%content
14+
close(file)
15+
else
16+
error stop response%err_msg
17+
end if
18+
19+
end program download_file

0 commit comments

Comments
 (0)