Last active
April 24, 2020 10:25
-
-
Save maxlapshin/cdf03656ac76431d9bede314f279b6b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1> {ok, Socket} = gen_tcp:connect("localhost", 80, [binary, {active,false}, {packet,http},inet]), | |
1> ok = gen_tcp:send(Socket, "GET /crossdomain.xml HTTP/1.0\r\n\r\n"), | |
1> | |
1> LoopHeaders = fun LoopHeaders(Len) -> | |
1> case gen_tcp:recv(Socket, 0) of | |
1> {ok, http_eoh} -> | |
1> inet:setopts(Socket, [{packet,raw}]), | |
1> Len; | |
1> {ok, {http_header,_,'Content-Length',_, Len_}} -> | |
1> LoopHeaders(list_to_integer(Len_)); | |
1> {ok, _} -> | |
1> LoopHeaders(Len) | |
1> end | |
1> end, | |
1> Length = LoopHeaders(undefined), | |
1> {ok, Bin} = gen_tcp:recv(Socket, Length), | |
1> io:format("~s\n", [Bin]), | |
1> gen_tcp:close(Socket). | |
<?xml version="1.0"?> | |
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> | |
<cross-domain-policy> | |
<allow-access-from domain="*" to-ports="*"/> | |
<site-control permitted-cross-domain-policies="all"/> | |
<allow-http-request-headers-from domain="*" headers="*" /> | |
</cross-domain-policy> | |
ok | |
2> f(). | |
ok | |
3> {ok, Socket} = gen_tcp:connect("localhost", 80, [{inet_backend,socket},binary, {active,false}, {packet,http},inet]), | |
3> ok = gen_tcp:send(Socket, "GET /crossdomain.xml HTTP/1.0\r\n\r\n"), | |
3> | |
3> LoopHeaders = fun LoopHeaders(Len) -> | |
3> case gen_tcp:recv(Socket, 0) of | |
3> {ok, http_eoh} -> | |
3> inet:setopts(Socket, [{packet,raw}]), | |
3> Len; | |
3> {ok, {http_header,_,'Content-Length',_, Len_}} -> | |
3> LoopHeaders(list_to_integer(Len_)); | |
3> {ok, _} -> | |
3> LoopHeaders(Len) | |
3> end | |
3> end, | |
3> Length = LoopHeaders(undefined), | |
3> {ok, Bin} = gen_tcp:recv(Socket, Length), | |
3> io:format("~s\n", [Bin]), | |
3> gen_tcp:close(Socket). | |
** exception error: no match of right hand side value {error,closed} | |
4> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment