Discussion:
making http request with gforth
Add Reply
o***@teletyp.ist
2024-12-26 12:40:33 UTC
Reply
Permalink
hi forthers,

I am trying to do a (very simple and naive) http-request
with gforth (current from git):

#+begin_src forth
require unix/socket.fs

: test-http
s" httpbin.org" 80 open-socket >r
s" GET / HTTP/1.1\nHost httpbin.org\n\n" r@ write-socket
r@ pad 80 read-socket
r> close-socket ;
#+end_src

but /read-socket/ doesn't return anything - result is pad 0 on
the stack.

probably I misunderstand howto use socket.fs?

additional question - has anyone already done bindings for
libcurl?

many thanks for any hints & merry christmas - okflo
josv
2024-12-27 15:33:05 UTC
Reply
Permalink
Post by o***@teletyp.ist
hi forthers,
I am trying to do a (very simple and naive) http-request
#+begin_src forth
require unix/socket.fs
: test-http
s" httpbin.org" 80 open-socket >r
r> close-socket ;
#+end_src
but /read-socket/ doesn't return anything - result is pad 0 on
the stack.
probably I misunderstand howto use socket.fs?
additional question - has anyone already done bindings for
libcurl?
many thanks for any hints & merry christmas - okflo
Try:
require unix/socket.fs

: test-http
s" httpbin.org" 80 open-socket >r
s" GET HTTP/1.1\nHost httpbin.org\n\n" r@ write-socket
200 ms
r@ pad 80 read-socket .s
r> close-socket
cr type ;

Result after: test-http

HTTP/1.1 400 Bad Request
Server: awselb/2.0
Date: Fri, 27 Dec 2024 15:25:43 GM

Note: The site begins with https in a browser!
Jos

--
okflo
2024-12-27 20:59:17 UTC
Reply
Permalink
Hoi Jos,
Post by o***@teletyp.ist
Post by o***@teletyp.ist
I am trying to do a (very simple and naive) http-request
#+begin_src forth
require unix/socket.fs
: test-http
s" httpbin.org" 80 open-socket >r
r> close-socket ;
#+end_src
[...]
additional question - has anyone already done bindings for
libcurl?
require unix/socket.fs
: test-http
s" httpbin.org" 80 open-socket >r
200 ms
r> close-socket
cr type ;
Result after: test-http
HTTP/1.1 400 Bad Request
Server: awselb/2.0
Date: Fri, 27 Dec 2024 15:25:43 GM
thanks - that did it - so at least from a conceptual point of view :) I
did it right...

but what would be right way to /wait/ for a response? 200ms is just a
guess, isn't it? :)
Post by o***@teletyp.ist
Note: The site begins with https in a browser!
yep, ssl/tls would be my next question, actually I hoped, someone could
point me to a library f.e. incorporating libcurl or something similar.
Post by o***@teletyp.ist
Jos
okflo
--
josv
2024-12-29 13:12:26 UTC
Reply
Permalink
Post by o***@teletyp.ist
Post by o***@teletyp.ist
hi forthers,
I am trying to do a (very simple and naive) http-request
#+begin_src forth
require unix/socket.fs
: test-http
s" httpbin.org" 80 open-socket >r
r> close-socket ;
#+end_src
but /read-socket/ doesn't return anything - result is pad 0 on
the stack.
probably I misunderstand howto use socket.fs?
additional question - has anyone already done bindings for
libcurl?
many thanks for any hints & merry christmas - okflo
require unix/socket.fs
: test-http
s" httpbin.org" 80 open-socket >r
200 ms
r> close-socket
cr type ;
Result after: test-http
HTTP/1.1 400 Bad Request
Server: awselb/2.0
Date: Fri, 27 Dec 2024 15:25:43 GM
Note: The site begins with https in a browser!
Jos
--
The 200 ms is indeed a crude way.
See https://www.gnu.org/software/libc/manual/html_node/Listening.html
for more details especially the pages about listing and accepting
connections

I never used ssl/tls.
Jos

--
d***@comcast.net
2025-01-09 03:05:44 UTC
Reply
Permalink
Post by o***@teletyp.ist
Post by o***@teletyp.ist
I am trying to do a (very simple and naive) http-request
...
Post by o***@teletyp.ist
require unix/socket.fs
: test-http
s" httpbin.org" 80 open-socket >r
200 ms
r> close-socket
cr type ;
Result after: test-http
HTTP/1.1 400 Bad Request
Server: awselb/2.0
Date: Fri, 27 Dec 2024 15:25:43 GM
If you make it GET / HTTP/1.1\nHost: httpbin.org\n\n (with slash as
minimal path in the first line and colon in the second) it should work
(but need a larger buffer). Officially the line ends should be CR LF
(\r\n) but many servers including this one accept LF.
Post by o***@teletyp.ist
Note: The site begins with https in a browser!
Not in my browsers. And it doesn't even serve HSTS, which would cause
a browser to force HTTPS on visits after the first.

Loading...